473,785 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Raising event to a different thread

jrh
Hi,
I am relatively new at threads. I have a windows form and a class running
on the same thread. The class has a background task that needs to be done
every minute on a background thread. I am still deciding on whether to use
System.Threadin g.Timer or Thread.Start/Thread.Sleep. The background task may
then raise an event which will be captured by the windows form. I believe
this event needs to be raised on the windows form thread. How do I go about
achieving this?
Nov 21 '05 #1
3 2199
Jrh,

When you want to use threading, ask yourself first why do I want to use
threading.
Be aware that it cost you at least more processing time.

When it are processes that take less than let say 3 seconds (and that is
terrible long for a modern computer), than it is already direct senseless to
use threading.

I hope this gives an idea.

Cor
Nov 21 '05 #2
"jrh" <jr*@discussion s.microsoft.com > schrieb
Hi,
I am relatively new at threads. I have a windows form and a class
running on the same thread. The class has a background task that
needs to be done every minute on a background thread. I am still
deciding on whether to use System.Threadin g.Timer or
Thread.Start/Thread.Sleep. The background task may then raise an
event which will be captured by the windows form. I believe this
event needs to be raised on the windows form thread. How do I go
about achieving this?


In the event handler, use the Form's Invoke/BeginInvoke method to marshal
the call to the other thread.

Armin

Nov 21 '05 #3
jrh
Thanks for the reply. I'm developing in layers i.e. User Interface layer,
Business Object Layer and Data layer. The task that I want to perform is
part of a business object. I would like to encapsulate it so the business
object event is raised on its thread (which is the same as the UI) instead of
the background thread. Therefore
the UI developer does not have to worry about calling Invoke. Also the UI
developer may not even be aware that threads are being used.

An idea I have is to add a private control to the business object. Then I
could use invoke to then raise the event on the business objects original
thread.
Will this work? Is there another method of marshalling a call to another
thread?
Nov 21 '05 #4

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

Similar topics

3
1955
by: James Dunkerley | last post by:
Hi, I am trying to create a class which downloads a web page in the background and then raises an event in the original thread in which it was created. This class is going to be the basis of a set of different applications and I want to hide the threading from the other layers. Any suggestions as to how to do this? Thanks James
6
2883
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
4
17270
by: rawCoder | last post by:
Hi all, How Can You Raise Events Asynchronously ? Now for the details ... I want to do inter modular communication using events in such a way that the contributing modules need not maintain the reference to any module.
3
2548
by: Chris Dunaway | last post by:
Consider the following simple classes/interfaces defined below. When the derived class raises the events, on which thread is the event code run? Do I need to do anything to catch the events in my main app? What threading issues do I have if several of these fileproc classes are instantiated and run at the same time? '*** BEGIN CODE Public Interface IFileProc ReadOnly Property FileMask() As String Function Process(ByVal filename As...
9
1834
by: CuriousGeorge | last post by:
Can someone explain why this code DOES NOT raise a null reference exception? //////////////////////////// Program.cs ///////////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; using CSharpLib;
1
1889
by: Asko Telinen | last post by:
Hi all. I ran into quite strange problem concerning the event raising inside FileSystemWatcher Delete event. First, i would like to describe a bit my environment. I have main GUI application, which uses other class libraries. One lib, called Utils.dll contains custom collection implementation. This simple collection just overrides Add and Remove methods to raise
3
1834
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, I have an app with the main thread and one additional thread. In the main thread I defined an event handler MyHandler, the function for raisin this event OnMyEvent and the function for processing this event MyFunc. I want to raise this event from the second thread. Is it thread safe to call the method OnMyEvent from this second thread?
1
1455
by: Ajak | last post by:
Hi all, I would like to write a class (Task) with a method to do some lengthy process based on several of the class properties. The method is running on different thread. During the execution of the method, the class is suppose to fire events such as ProgressChanged. And it raises Completed and Failed event on completion and error
26
1675
by: buu | last post by:
So, let's say that a user enters an event name in text box, and would like to raise it.. is it possible to call events by their 'name'? Is it possible to enumerate events inside app. and to check their names?
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10327
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.