.net 2.0 -> "InvalidOperationException" at DebugTime

H

Horst Klein

Mit dem Framework 2.0 habe ich ein Problem das ich vorher nicht hatte.
Oder es zumindest nicht festgestellt habe.


In my Application I show each seconnd the Time in a statusbar.
At runtim it works fine. If I want debug, fires an
"InvalidOperationException".
Is it my bug or a bug in VS2005 Beta2?

Here the code to reproduce it
Imports System.Globalization
Public Class Form1

Private m_DateTimer As New System.Timers.Timer
Private m_DateThread As Threading.Thread

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
m_DateThread = New Threading.Thread(AddressOf UpdateTime)
m_DateThread.Priority = Threading.ThreadPriority.Lowest
m_DateThread.Start()
End Sub

Private Sub RefreshDate(ByVal source As Object, ByVal e As
System.Timers.ElapsedEventArgs)
Me.Text = DateTime.Today.GetDateTimeFormats("d"c,
CultureInfo.CurrentUICulture)(0).ToString
End Sub

Private Sub UpdateTime()
AddHandler m_DateTimer.Elapsed, AddressOf RefreshDate
m_DateTimer.Interval = 1000
m_DateTimer.Enabled = True
End Sub

End Class
 
C

cody

Wasn das? Denglisch?

In VS2005 ist es nicht mehr zulässig das Anwendungen Methoden oder
Properties von Controls wie bei dir "Me.Text=" von einem anderen Thread als
dem GUI-Thread aufrufen. Aus Kompatibilitätsgründen wird die Exception
allerdings nur im Debugmodus ausgelöst. Du solltest also immer mit
BeginInvoke() die Aufrufe zum GUI-Thread marshallen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top