How to Marshal a call to Timer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Esteemed Developers and Esteemed Experts,

I have a background-running-thread in my application that is designed and developed at Windows Forms (.NET) by using Visual C++ .NET Standard on Windows 2000 Professional O.S.

Whenever the required job is done in that background-running-thread, I would like to Enable and Start the Timer to do the related job from the background-running-thread.

It is written in MSDN Library that "It requires that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread." I understood that I need to marshal the call the starting and enabling statements.

Due to being new in Visual C++ .NET, I don't know how to marshal it.

Please kindly guide me. I thank your kind considerations in advance

Respectfully, yours
 
Hi BilMuh,

Look at Control.Invoke and Control.BeginInvoke methods. They are meant to be
used for marshaling method calls form worker threads to UI threads (threads
that have message pump). Marshaling calls from UI thread to worker thread is
not trivial (it is not supported in the framework) because whether it is
possible or not depends on the code that the thread executes.

You can also take a look at the others 2 timers - System.Threading.Timer and
System.Timers.Timer. They don't have the limitations
System.Windows.Forms.Timer timer has, but their tick events are executed in
a worker thread and if you want to work with the UI from the event handlers
you will run into the the same problem with marshaling calls to the UI
thread.

However System.Timers.Timer has one property called SynchronizingObject. If
you set this property to reference some form or control of yours the timer
class will marchal the event to the UI threads that has created that control
or form for you, so you don't have to do anything. Just go to the Toolbox's
Components tab and drag the timer control from there. The designer will take
care of the rest.
--
HTH
Stoitcho Goutsev (100) [C# MVP]


BilMuh said:
Hello Esteemed Developers and Esteemed Experts,

I have a background-running-thread in my application that is designed and
developed at Windows Forms (.NET) by using Visual C++ .NET Standard on
Windows 2000 Professional O.S.
Whenever the required job is done in that background-running-thread, I
would like to Enable and Start the Timer to do the related job from the
background-running-thread.
It is written in MSDN Library that "It requires that the user code have a
UI message pump available and always operate from the same thread, or
marshal the call onto another thread." I understood that I need to marshal
the call the starting and enabling statements.
 
Esteemed Goutsev,

I would like to thank Your Kind Considerations.

Best Regards,

Bil Muh
 
Back
Top