Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2004

Tip: Looking for answers? Try searching our database.

Delegates and Threads

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Howard Weiss - 03 Sep 2004 21:38 GMT
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);
Howard Weiss - 04 Sep 2004 13:31 GMT
The solution was to use Invoke as follows

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

rather than

pShow_>Invoke()

Howard Weiss

>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
[quoted text clipped - 40 lines]
> Howard Weiss
> __delegate void delegateImageActivated(int Index);

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.