473,395 Members | 1,978 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,395 software developers and data experts.

Are events threaded by default?

Say I have two seperate timers in my app (it's strictly an example, I
don't really...) and each of the timer events calls the same method of the
form's class. Will these interfere with each other at all? Will they run
as if they're threaded?

Example:

private void timer1_Tick(object sender, System.EventArgs e)
{
this.SomeMethod()
}

private void timer2_Tick(object sender, System.EventArgs e)
{
this.SomeMethod()
}

private string SomeMethod()
{
OleDbCommand oDB = new OleDbCommand();
oDB.COnnection = new OleDbConnection(this.DSNString);

// do a bunch of other stuff

oDB.Connection.Close();
oDB.Dispose();
}
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Nov 22 '05 #1
2 1388
JSheble <js***********@logicor.com> wrote:
Say I have two seperate timers in my app (it's strictly an example, I
don't really...) and each of the timer events calls the same method of the
form's class. Will these interfere with each other at all? Will they run
as if they're threaded?


Are you interested in timers, or events in general? Events have no
special threading behaviour - whereas timers do, and the exact
semantics depend on which type of timer you're talking about.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
I'm assuming you're using the System.Windows.Forms.Timer (based on the
name of the handler). If that's the case then no, events will be
executed on the main UI thread and thus will not interfere with each
other since the message pump will process them serially.

If you're using the System.Timers.Timer then events might be executed
on different threads depending on the how the SynchronizingObject
property is set. The SynchronizingObject property accepts an
ISynchronizeInvoke object. Forms and controls implement this interface
so if they are used then the timer events will be executed on a UI
thread. If the SynchronizingObject property is null then the timer
events are executed from threads in the system thread pool.

The other timer, which I know you're not speaking of, is
System.Threading.Timer. That timer always invokes the specified
callback from a thread in the thread pool.

Brian

JSheble wrote:
Say I have two seperate timers in my app (it's strictly an example, I
don't really...) and each of the timer events calls the same method of the
form's class. Will these interfere with each other at all? Will they run
as if they're threaded?

Example:

private void timer1_Tick(object sender, System.EventArgs e)
{
this.SomeMethod()
}

private void timer2_Tick(object sender, System.EventArgs e)
{
this.SomeMethod()
}

private string SomeMethod()
{
OleDbCommand oDB = new OleDbCommand();
oDB.COnnection = new OleDbConnection(this.DSNString);

// do a bunch of other stuff

oDB.Connection.Close();
oDB.Dispose();
}
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Nov 22 '05 #3

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

Similar topics

2
by: JSheble | last post by:
Say I have two seperate timers in my app (it's strictly an example, I don't really...) and each of the timer events calls the same method of the form's class. Will these interfere with each other...
2
by: Gulshan Oshan | last post by:
I want to implement a simple console that continuously listens for an event from a custom object. I am unable to capture the events from the object. If I subscribe to the events in a windows app...
3
by: Jacob | last post by:
I'm working on a class that needs to be called from a windows form, do it's work, and then, show progress back to the main form. I'm well aware that worker threads need to call Invoke for updates...
1
by: SPG | last post by:
Hi, We have a standard windows app writeen in C# that uses an ActiveX dll to send us events. This works fine as a Windows app, but as soon as we compile as a service, no more events. I have...
1
by: Bruce M. Carroll | last post by:
I am doing some work a distributed application, which uses events and remoting to accomplish the signaling between applications. This all works. The problem I have (I think) is that since...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
3
by: Naveen Mukkelli | last post by:
Hi, I'm trying to update my GUI when an event is raised in my one of my dlls. my example code is: ------------------- In GUI: someLable.Text = " "; ---
6
by: ankurw | last post by:
Hi All, I am experiencing a frustrating issue with hooking into COM events from a Windows service writting in C#. I create a COM object in the service and hook into an event exposed by the...
0
by: BigAl.NZ | last post by:
Hi Guys, I am trying to write/copy some code that uses events with a GPS. Everytime the GPS position updates the event fires. The GPS code is from a SDK Library that I got called GPS Tools...
15
by: colin | last post by:
Hi, Im familiar with c,c++ etc, and Ive spent a week trying to write my first app in c# it works reasonably well, but im having difficulty getting to grips with inter thread signalling etc. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.