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

Delegates and Threads

I am writing a Managed C++ image processing application which consists of a
main window and a number of image processing windows. The main window is a
Windows Forms and each image window is an instance of a different Windows
Form. The image windows are created by creating New instances of the image
form. The image forms become visible when I invoke show method.

Initially, I wrote my application as a single threaded application.
However, it takes considerable time to generate the images and I wish to
keep my UI interactive, so I am converting to a multi-threaded application.
At first, I created the image and invoked the show method for the images in
the worker thread. The images disappeared as soon as the worker thread
completes. I therefore created a delegate to invoke the show method from
within my UI thread.

Code in my main thread looks like

showImage(Image *Image)
{
Image->Show();
}

Code in my worker thread looks like

__delegate void delegateImageShow(Image *Image);

....
Image *pImageToDisplay;
delegateImageShow *pShow = new delegateImageShow(this, showImage);
pShow->Invoke(pImageToDisplay)
....

However, if I look at the HashCode of the thread which is running showImage,
it is the HashCode of the worker thread and not the HashCode of my UI
thread.

I am puzzled

Howard Weiss
__delegate void delegateImageActivated(int Index);

Nov 17 '05 #1
1 1031
The solution was to use Invoke as follows

....
Object *pObject[] = {__box(pImage)};
Invoke(pShow, pObject);
.....

rather than

pShow_>Invoke()

Howard Weiss

"Howard Weiss" <hp*****@comcast.net> wrote in message
news:OF**************@TK2MSFTNGP15.phx.gbl...
I am writing a Managed C++ image processing application which consists of a
main window and a number of image processing windows. The main window is
a
Windows Forms and each image window is an instance of a different Windows
Form. The image windows are created by creating New instances of the
image
form. The image forms become visible when I invoke show method.

Initially, I wrote my application as a single threaded application.
However, it takes considerable time to generate the images and I wish to
keep my UI interactive, so I am converting to a multi-threaded
application.
At first, I created the image and invoked the show method for the images
in
the worker thread. The images disappeared as soon as the worker thread
completes. I therefore created a delegate to invoke the show method from
within my UI thread.

Code in my main thread looks like

showImage(Image *Image)
{
Image->Show();
}

Code in my worker thread looks like

__delegate void delegateImageShow(Image *Image);

...
Image *pImageToDisplay;
delegateImageShow *pShow = new delegateImageShow(this, showImage);
pShow->Invoke(pImageToDisplay)
...

However, if I look at the HashCode of the thread which is running
showImage,
it is the HashCode of the worker thread and not the HashCode of my UI
thread.

I am puzzled

Howard Weiss
__delegate void delegateImageActivated(int Index);

Nov 17 '05 #2

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

Similar topics

5
by: Marina | last post by:
Hi, we have an app, that executes jobs submitted from an outside application. It executes them asynchronusly, by creating a delegate to the method that can run the job, and calling BeginInvoke on...
12
by: Joey Powell | last post by:
Re: Original post = Windows forms - how do I get them to render/update properly? from August 22. Okay I am making some progress with being able to use delegates to run my shelled processes on...
2
by: rb531 | last post by:
Guys, I am struck up with a dilemma whether to use threading or delgates for asynchronous processing. Can anyone throw some light on this? Please let me know which one is better. Thanks
4
by: Bob Rock | last post by:
Hello, I was wondering if callback delegates, called in response to a event, are executed in their own thread. I was suspecting the OS might spawn a new thread and have the delegate execute in...
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...
12
by: Grant | last post by:
I am having great difficulty understanding this and any code samples I find online are kilometres long and complicated to understand...Please could someone give me a simple exampe of how to get a...
14
by: Lior Amar | last post by:
Quick question about threads and delegates. I have the following scenario Thread A (CLASSA) spawns Thread B (CLASSB) and passes it a DelegateA to a callback Thread B Invokes a DelegateB...
2
by: Viet | last post by:
I have a couple of questions that hopefully someone could clarify for me. I have an app that uses the threading.timer to constantly poll a scanner to scan in documents. I understand that Async...
13
by: heddy | last post by:
Using Jesse Liberty's excellent book on C#, I am looking at chapter 12 - Delegates. Now, I was under the impression that a delegate is essentially a pointer to a member function. However, when I...
6
by: Jon Davis | last post by:
I've used delegates fairly heavily for several years in C# for event handling and for starting threads. Does anyone have any real-world scenarios where delegates were both extremely useful and...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.