Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

I have a form in which I have to do some treatment every X seconds.

So first, I have created a wrapper of System.Windows.Forms.Timer class to execute some code every X seconds. It is working fine.

The only disadventage of that solution is that the timer and the main form run in the same thread.

As the treatment has begun quite time consuming, I have decided to let it work in a separate thread.

So I had :

1. Transformed my wrapper to be a wrapper of System.Timers.Timer class (which will run in a separate thread)

2. Synchronized some critical method

3. Synchronized some data by using the ReaderLock and WriterLock

4. Modified the UI functions called by the separate thread like that :

 

public sub MyThreadSafeUIMethod()
 If Me.InvokeRequired
   Me.Invoke(new MethodInvoker(addressof me.MyThreadSafeUIMethod))
 else
   ' -- Do my stuff on UI
 end if
end sub

 

And for a reason I do not uderstand at all, my code doesn't work. There is no exception, it is "just" blocked on the Invoke call, as it didn't find the main UI thread.

I have tried to reproduce that case on a small exemple but of course, it works perfectly. I have no idea why the call to Invoke can fail.

The main thread is surely not stopped or suspended (the "thread debug windows" indicates it as running)

 

Any idea of what can happen ?

Jarod
  • 1 month later...
Posted

No sorry...

I just kept my System.Windows.Forms.Timer for now...

I haven't found any solution and couldn't reproduce that problem in a simple sample.

Jarod

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...