473,327 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Threading Timer_Elapsed

Hello,

I'm a new user to Visual Basic.net and I would appreciate any help regarding
a problem I have. I have searched the posts in this newsgroup and the VB
library for threading topics, but I get confused with the code that is
displayed. Anyway, I have a System.Timers.Timer object in a form and its
interval is 50 ms. I want to create a thread around the Timer_Elapsed event
(ie. myThread = new System.Threading.Thread(AddressOf Timer_Elapsed)) but
the signature doesn't match the delegate. Could someone please tell me how
to create a thread around this event? I did look up Threaded Timers but I
got even more confused with the code. Thanks in advance.
Nov 21 '05 #1
8 2427

"NewUser" <Ne*****@discussions.microsoft.com> wrote
Hello,

I'm a new user to Visual Basic.net and I would appreciate any help regarding
a problem I have.
You may want to include what you plan to do, so that advice can be given
on methods to achieve the task....
Anyway, I have a System.Timers.Timer object in a form and its
interval is 50 ms. I want to create a thread around the Timer_Elapsed event
(ie. myThread = new System.Threading.Thread(AddressOf Timer_Elapsed)) but
the signature doesn't match the delegate. Could someone please tell me how
to create a thread around this event? I did look up Threaded Timers but I
got even more confused with the code. Thanks in advance.


Which is why you should give some indication about what you want to
accomplish with your added thread. The form's timer runs on the form's
thread, where you can interact with the form. A system timer runs on a
thread from a pool of threads, where interacting with your form will be
made more complex.

What do you want the thread for?

LFS
Nov 21 '05 #2
Hello again,

I have a graphical user interface that requires a Matlab program to be run
every 50 ms or so. In my Timer_Elapsed event, I only execute the following
code:
mlapp.Execute("Runsim") where mlapp is the COM object (ie using
CreateObject("Matlab.Application")) and Runsim is the name of the Matlab
program I'm calling. I would do all of this in Matlab GUIDE, but my version
of Matlab does not support the ActiveX controls that I need. Anyway, since
the Matlab program is rather large and the interval required is small, my GUI
will freeze up. Therefore, I'm trying to make a separate thread to run this
Timer_Elapsed event so repainting isn't affected too much. I hope that helps
you to give me a better indication of what to do. Thanks in advance again.
Nov 21 '05 #3

"NewUser" <Ne*****@discussions.microsoft.com> wrote
I have a graphical user interface that requires a Matlab program to be run
every 50 ms or so. In my Timer_Elapsed event, I only execute the following
code:
mlapp.Execute("Runsim") where mlapp is the COM object (ie using
CreateObject("Matlab.Application")) and Runsim is the name of the Matlab
program I'm calling. I would do all of this in Matlab GUIDE, but my version
of Matlab does not support the ActiveX controls that I need. Anyway, since
the Matlab program is rather large and the interval required is small, my GUI
will freeze up. Therefore, I'm trying to make a separate thread to run this
Timer_Elapsed event so repainting isn't affected too much. I hope that helps
you to give me a better indication of what to do. Thanks in advance again.

Well, NewUser, do you really want to tackle advanced COM interop on your
first time out? Mixing threads for what very well may need to be single threaded
may not be the way to go, but I'll defer to anyone else who can provide more
experience, because my experience with COM interop proxies is next to nothing.

If it were me, I'd look into creating one assembly to handle the Matlab program,
and a second assembly to handle the GUI and provide methods or events to
transfer data between the two. But again, wait for other replies to perhaps find
someone with more experience with what you want to do. If you don't see any
replies by tomorrow at this time, post a new message with 'COM Interop threading'
in the subject line and repeat what you want to do, like you stated above. Maybe
that will better attract those with experience in that area....

Good luck!
LFS
Nov 21 '05 #4

"NewUser" <Ne*****@discussions.microsoft.com> wrote
I have a graphical user interface that requires a Matlab program to be run
every 50 ms or so. In my Timer_Elapsed event, I only execute the following
code:
mlapp.Execute("Runsim") where mlapp is the COM object (ie using
CreateObject("Matlab.Application")) and Runsim is the name of the Matlab
program I'm calling. I would do all of this in Matlab GUIDE, but my version
of Matlab does not support the ActiveX controls that I need. Anyway, since
the Matlab program is rather large and the interval required is small, my GUI
will freeze up. Therefore, I'm trying to make a separate thread to run this
Timer_Elapsed event so repainting isn't affected too much. I hope that helps
you to give me a better indication of what to do. Thanks in advance again.

Well, NewUser, do you really want to tackle advanced COM interop on your
first time out? Mixing threads for what very well may need to be single threaded
may not be the way to go, but I'll defer to anyone else who can provide more
experience, because my experience with COM interop proxies is next to nothing.

If it were me, I'd look into creating one assembly to handle the Matlab program,
and a second assembly to handle the GUI and provide methods or events to
transfer data between the two. But again, wait for other replies to perhaps find
someone with more experience with what you want to do. If you don't see any
replies by tomorrow at this time, post a new message with 'COM Interop threading'
in the subject line and repeat what you want to do, like you stated above. Maybe
that will better attract those with experience in that area....

Good luck!
LFS
Nov 21 '05 #5
In article <FF**********************************@microsoft.co m>, NewUser wrote:
Hello,

I'm a new user to Visual Basic.net and I would appreciate any help regarding
a problem I have. I have searched the posts in this newsgroup and the VB
library for threading topics, but I get confused with the code that is
displayed. Anyway, I have a System.Timers.Timer object in a form and its
interval is 50 ms. I want to create a thread around the Timer_Elapsed event
(ie. myThread = new System.Threading.Thread(AddressOf Timer_Elapsed)) but
the signature doesn't match the delegate. Could someone please tell me how
to create a thread around this event? I did look up Threaded Timers but I
got even more confused with the code. Thanks in advance.


The system.timers.timer event happens on a separate thread already,
there is nothing to do there.

Wait a minute... Your using this in a form from the ide aren't you? If
that's the case, and you aren't going to be accessing the GUI, then you
need to set the timers SynchronizingObejct property to nothing, or it
will automatically marshal the event to your forms thread...

Another thing - you may experience problems with your COM object on the
other thread if it isn't an MTA capable object. If that's the case,
you'll need to spawn the thread manually and set it's apartmentstate to
STA. Then you would have to do something like:

do until teminateflag
call yourbobject
thread.sleep (50)
loop

And remember, you can't directly access your form from any of these
threads. If you need to access the GUI, you'll need to look at the
following article:

http://msdn.microsoft.com/library/de...ms06112002.asp

this is part 1 of a 3 part article. You should read them all.

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 37 Days, 23 Hours, 23 Minutes, 47 Seconds
Nov 21 '05 #6
In article <FF**********************************@microsoft.co m>, NewUser wrote:
Hello,

I'm a new user to Visual Basic.net and I would appreciate any help regarding
a problem I have. I have searched the posts in this newsgroup and the VB
library for threading topics, but I get confused with the code that is
displayed. Anyway, I have a System.Timers.Timer object in a form and its
interval is 50 ms. I want to create a thread around the Timer_Elapsed event
(ie. myThread = new System.Threading.Thread(AddressOf Timer_Elapsed)) but
the signature doesn't match the delegate. Could someone please tell me how
to create a thread around this event? I did look up Threaded Timers but I
got even more confused with the code. Thanks in advance.


The system.timers.timer event happens on a separate thread already,
there is nothing to do there.

Wait a minute... Your using this in a form from the ide aren't you? If
that's the case, and you aren't going to be accessing the GUI, then you
need to set the timers SynchronizingObejct property to nothing, or it
will automatically marshal the event to your forms thread...

Another thing - you may experience problems with your COM object on the
other thread if it isn't an MTA capable object. If that's the case,
you'll need to spawn the thread manually and set it's apartmentstate to
STA. Then you would have to do something like:

do until teminateflag
call yourbobject
thread.sleep (50)
loop

And remember, you can't directly access your form from any of these
threads. If you need to access the GUI, you'll need to look at the
following article:

http://msdn.microsoft.com/library/de...ms06112002.asp

this is part 1 of a 3 part article. You should read them all.

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 37 Days, 23 Hours, 23 Minutes, 47 Seconds
Nov 21 '05 #7
NewUser,
In addition to the other comments (especially Tom's about the
SynchronizingObject property).

The following article in MSDN Magazine explains the difference between the
three timer objects in .NET & when to use each.

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

The above article also discusses if & how each timer interacts with
threading.

Hope this helps
Jay
"NewUser" <Ne*****@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
Hello,

I'm a new user to Visual Basic.net and I would appreciate any help
regarding
a problem I have. I have searched the posts in this newsgroup and the VB
library for threading topics, but I get confused with the code that is
displayed. Anyway, I have a System.Timers.Timer object in a form and its
interval is 50 ms. I want to create a thread around the Timer_Elapsed
event
(ie. myThread = new System.Threading.Thread(AddressOf Timer_Elapsed)) but
the signature doesn't match the delegate. Could someone please tell me
how
to create a thread around this event? I did look up Threaded Timers but I
got even more confused with the code. Thanks in advance.

Nov 21 '05 #8
NewUser,
In addition to the other comments (especially Tom's about the
SynchronizingObject property).

The following article in MSDN Magazine explains the difference between the
three timer objects in .NET & when to use each.

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

The above article also discusses if & how each timer interacts with
threading.

Hope this helps
Jay
"NewUser" <Ne*****@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
Hello,

I'm a new user to Visual Basic.net and I would appreciate any help
regarding
a problem I have. I have searched the posts in this newsgroup and the VB
library for threading topics, but I get confused with the code that is
displayed. Anyway, I have a System.Timers.Timer object in a form and its
interval is 50 ms. I want to create a thread around the Timer_Elapsed
event
(ie. myThread = new System.Threading.Thread(AddressOf Timer_Elapsed)) but
the signature doesn't match the delegate. Could someone please tell me
how
to create a thread around this event? I did look up Threaded Timers but I
got even more confused with the code. Thanks in advance.

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
6
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine , but final process (3) doesnt get called. i stop and restart the windows service...
2
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True...
11
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
4
by: TampaWebDevelopment | last post by:
I am writing a FTP backup service for my servers. Right now, it works well, but it is single threaded and takes a couple of hours to complete a backup of the websites directory, even to a server on...
1
by: raghulvarma | last post by:
Hai friends, I have to get a timer in my asp form, What is the difference between timer_elapsed and timer_tick (c# .net) .I am able to make the timer work in c# but in asp.net i am not able...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.