473,399 Members | 3,656 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,399 software developers and data experts.

dispatch

Hi,

How can I dispatch something from a worker thread to the UI thread ?

Thanks in advance
greetings
Nov 15 '05 #1
8 2478

"Jhon" <Jh**@a.a> wrote in message
news:K9*********************@phobos.telenet-ops.be...
Hi,

How can I dispatch something from a worker thread to the UI thread ?

Thanks in advance
greetings

Read about Form.Invoke. The following code should give you the idea:

public class Foo
{
public MyFormClass TheForm; //has a TextBox called textBox; inherits
//from System.Windows.Forms.Form

public delegate void UIMessageHandler(String msg);
public static UIMessageHandler OnUIMsgProxy;

public Foo(MyFormClass form)
{

OnUIMsgProxy = new UIMessageHandler(OnUIMsg);
TheForm = form;
}

public static void OnUIMsg(String msg) //invoked on UI thread
{
//add new msg to the top of the current text
String curText = TheForm.textBox.Text;
if (curText.Length > 28000)
curText = curText.Substring(0,25000);
TheForm.textBox.Text = msg + "\r\n" + curText;
TheForm.textBox.Refresh();
}
/*
To insert text to the UI from another thread, the other thread calls:
Foo.UIMsgInvoke("here is some text for the UI");
/*
public static void UIMsgInvoke(String str)
{
//invoke the message writer on the UI thread
Object [] msg = new Object[1];
msg[0] = str;

if (TheForm.IsHandleCreated)
TheForm.Invoke(OnUIMsgProxy, msg);

}
}
Nov 15 '05 #2

"Jhon" <Jh**@a.a> wrote in message
news:K9*********************@phobos.telenet-ops.be...
Hi,

How can I dispatch something from a worker thread to the UI thread ?

Thanks in advance
greetings

Read about Form.Invoke. The following code should give you the idea:

public class Foo
{
public MyFormClass TheForm; //has a TextBox called textBox; inherits
//from System.Windows.Forms.Form

public delegate void UIMessageHandler(String msg);
public static UIMessageHandler OnUIMsgProxy;

public Foo(MyFormClass form)
{

OnUIMsgProxy = new UIMessageHandler(OnUIMsg);
TheForm = form;
}

public static void OnUIMsg(String msg) //invoked on UI thread
{
//add new msg to the top of the current text
String curText = TheForm.textBox.Text;
if (curText.Length > 28000)
curText = curText.Substring(0,25000);
TheForm.textBox.Text = msg + "\r\n" + curText;
TheForm.textBox.Refresh();
}
/*
To insert text to the UI from another thread, the other thread calls:
Foo.UIMsgInvoke("here is some text for the UI");
/*
public static void UIMsgInvoke(String str)
{
//invoke the message writer on the UI thread
Object [] msg = new Object[1];
msg[0] = str;

if (TheForm.IsHandleCreated)
TheForm.Invoke(OnUIMsgProxy, msg);

}
}
Nov 15 '05 #3
that will do it,
Thanks,
Greetings

"Fred Mellender" <no****************@frontiernet.net> wrote in message
news:i3************@news01.roc.ny...

"Jhon" <Jh**@a.a> wrote in message
news:K9*********************@phobos.telenet-ops.be...
Hi,

How can I dispatch something from a worker thread to the UI thread ?

Thanks in advance
greetings

Read about Form.Invoke. The following code should give you the idea:

public class Foo
{
public MyFormClass TheForm; //has a TextBox called textBox; inherits
//from System.Windows.Forms.Form

public delegate void UIMessageHandler(String msg);
public static UIMessageHandler OnUIMsgProxy;

public Foo(MyFormClass form)
{

OnUIMsgProxy = new UIMessageHandler(OnUIMsg);
TheForm = form;
}

public static void OnUIMsg(String msg) //invoked on UI thread
{
//add new msg to the top of the current text
String curText = TheForm.textBox.Text;
if (curText.Length > 28000)
curText = curText.Substring(0,25000);
TheForm.textBox.Text = msg + "\r\n" + curText;
TheForm.textBox.Refresh();
}
/*
To insert text to the UI from another thread, the other thread calls:
Foo.UIMsgInvoke("here is some text for the UI");
/*
public static void UIMsgInvoke(String str)
{
//invoke the message writer on the UI thread
Object [] msg = new Object[1];
msg[0] = str;

if (TheForm.IsHandleCreated)
TheForm.Invoke(OnUIMsgProxy, msg);

}
}

Nov 15 '05 #4
that will do it,
Thanks,
Greetings

"Fred Mellender" <no****************@frontiernet.net> wrote in message
news:i3************@news01.roc.ny...

"Jhon" <Jh**@a.a> wrote in message
news:K9*********************@phobos.telenet-ops.be...
Hi,

How can I dispatch something from a worker thread to the UI thread ?

Thanks in advance
greetings

Read about Form.Invoke. The following code should give you the idea:

public class Foo
{
public MyFormClass TheForm; //has a TextBox called textBox; inherits
//from System.Windows.Forms.Form

public delegate void UIMessageHandler(String msg);
public static UIMessageHandler OnUIMsgProxy;

public Foo(MyFormClass form)
{

OnUIMsgProxy = new UIMessageHandler(OnUIMsg);
TheForm = form;
}

public static void OnUIMsg(String msg) //invoked on UI thread
{
//add new msg to the top of the current text
String curText = TheForm.textBox.Text;
if (curText.Length > 28000)
curText = curText.Substring(0,25000);
TheForm.textBox.Text = msg + "\r\n" + curText;
TheForm.textBox.Refresh();
}
/*
To insert text to the UI from another thread, the other thread calls:
Foo.UIMsgInvoke("here is some text for the UI");
/*
public static void UIMsgInvoke(String str)
{
//invoke the message writer on the UI thread
Object [] msg = new Object[1];
msg[0] = str;

if (TheForm.IsHandleCreated)
TheForm.Invoke(OnUIMsgProxy, msg);

}
}

Nov 15 '05 #5
Fred Mellender <no****************@frontiernet.net> wrote:
Read about Form.Invoke. The following code should give you the idea:


<snip>

Just to be a bit more precise, it's not Form.Invoke but Control.Invoke.
This is handy as it means you don't need to find out which form a
control belongs to before invoking something on its UI thread.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Fred Mellender <no****************@frontiernet.net> wrote:
Read about Form.Invoke. The following code should give you the idea:


<snip>

Just to be a bit more precise, it's not Form.Invoke but Control.Invoke.
This is handy as it means you don't need to find out which form a
control belongs to before invoking something on its UI thread.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Fred Mellender <no****************@frontiernet.net> wrote:
Read about Form.Invoke. The following code should give you the idea:
<snip>

Just to be a bit more precise, it's not Form.Invoke but Control.Invoke.
This is handy as it means you don't need to find out which form a
control belongs to before invoking something on its UI thread.


oh, I see
that's usefull to know

thanks!


--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #8

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Fred Mellender <no****************@frontiernet.net> wrote:
Read about Form.Invoke. The following code should give you the idea:
<snip>

Just to be a bit more precise, it's not Form.Invoke but Control.Invoke.
This is handy as it means you don't need to find out which form a
control belongs to before invoking something on its UI thread.


oh, I see
that's usefull to know

thanks!


--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #9

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

Similar topics

3
by: RJ | last post by:
Hi, I've been going over the Quick Start to Client side COM and Python and many other sources, but cannot find an example that will get my com/ActiveX .ocx USB device driver imported. The Excel...
3
by: Dan Vogel | last post by:
I'd like to find an elegant solution to the problem of calling a certain function based on the types of two parameters. In my case, the functions compute the distance between different types of...
3
by: muttu2244 | last post by:
Hi all Am trying to read an html page using win32com in the following way. from win32com.client import Dispatch ie = Dispatch("InternetExplorer.Application")
3
by: tyler.schlosser | last post by:
Hi there, I am trying to launch a program called AmiBroker using the command: AB = win32com.client.Dispatch("Broker.Application") However, I have a dual-core CPU and would like to launch two...
4
by: mirandacascade | last post by:
O/S : Win2K vsn of Python: 2.4 Hoping to find information that provide information about error messages being encountered. Pythonwin session: Traceback (most recent call last): File...
2
by: jiccab | last post by:
Greetings. with the following code, olApp = Dispatch("Outlook.Application") I am capable of getting a new instance of Outlook running. I would like to be able to use the instance that is...
5
by: markww | last post by:
Hi, Can someone explain to me what static and dynamic dispatch are and what the difference is between the two? Do this even occurr in C++? Thanks
4
by: vithi | last post by:
Hi' I am trying to launch an application. When I try like that When I try like that Excel is opening import win32com.client object = win32com.client.Dispatch("Excel.Application") object.Visible...
3
by: Tigera | last post by:
Greetings, I too have succumbed to the perhaps foolish urge to write a video game, and I have been struggling with the implementation of multiple dispatch. I read through "More Effective C++"...
2
by: lialie | last post by:
Hi, Maybe it 's quite simple, but I can't fix it. Do I make some mistakes in my env setting? My excel version is 2003. any suggestion? Thanks. Traceback (most recent call last): File...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.