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 / Windows Forms / WinForm Controls / July 2007

Tip: Looking for answers? Try searching our database.

cross thread operation and invoke

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shyamvs.prasad@gmail.com - 24 Jul 2007 23:59 GMT
there is a line of code
Form.VisibleChanged += Form.Invoke(new EventHandler(abc));

it says that right hand side returns an object and left side expects
System.eventhandler
and if i remove the invoke line while running i get the exception that
cross thread operation is invalid

how do i handle this so that on whenever the visiblechanged property
value changes that function abc() is executed ?
of course using this invoke
ClayB - 25 Jul 2007 09:27 GMT
Maybe code such as this will serve your purposes.

//subscribe to the event is form load
this.VisibleChanged += new EventHandler(Form1_VisibleChanged);

//the event handler checks to see if it is on the proper thread and if
not, does an Invoke to come back in on the proper thread.

       void Form1_VisibleChanged(object sender, EventArgs e)
       {
           if (this.InvokeRequired)
           {
               this.Invoke(new EventHandler(Form1_VisibleChanged),
new object[] { sender, e });
           }
           else
           {
              //do whatever your want on the form's thread
           }
       }

===================
Clay Burch
Syncfusion, Inc.
shyamvs.prasad@gmail.com - 25 Jul 2007 14:58 GMT
I did as you said above but i still get the cross thread operation not
permitted
Sheng Jiang[MVP] - 25 Jul 2007 19:10 GMT
Using C# Anonymous Methods with Control.Invoke()
Invoke((MethodInvoker)delegate() {
//your statement here
});

Signature

Sheng Jiang
Microsoft MVP in VC++

> there is a line of code
> Form.VisibleChanged += Form.Invoke(new EventHandler(abc));
[quoted text clipped - 7 lines]
> value changes that function abc() is executed ?
> of course using this invoke

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.