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 / Visual J# / November 2005

Tip: Looking for answers? Try searching our database.

Marine Biology Simulation w/J# 2005 Express

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom Connors - 25 Nov 2005 23:36 GMT
I downloaded the MS Marine Biology Simulation for J#. The Conversion to J#
2005 went w/o errors. But when I run it, I get:

  Cross-thread operation not valid: Control 'pond21' accessed from
  a thread other than the thread it was created on.

What gives?
Diganta Roy[MSFT] - 28 Nov 2005 10:23 GMT
Hi Tom,

Thanks for reporting this issue.

We are aware of this and are on the way to upload the updated MBS Case
Study for VS 2005.

To unblock you, I will first describe what the issue is and how to fix it.

Issue:
The case study had a bug in the sense that; in it, an object called
'pond21'(which is a Winforms Control) is accessed from different threads.
"Access to Windows Forms controls is not inherently thread safe. If you
have two or more threads manipulating the state of a control, it is
possible to force the control into an inconsistent state".
From .Net 2.0 (VS 2005 i.e.) onwards the debugger is going to inform the
developer that a control is accessed from a thread different from the one
that created it - the debugger will be raising an InvalidOperationException
in such a case.

Fix:
'Refresh()' - This method in the Winforms Control 'Pond' is accessed from a
thread different from the one that created the control. What we are
essentially doing is synchronizing all calls to the method 'Refresh()'.
Change "public void showEnv()" in Pond.jsl to <<
          public void showEnv()  {
           /**  This method is called from more than one threads.
Following if block is there to avoid unsynchronized access **/
           if (this.get_InvokeRequired())            {
                 this.BeginInvoke(new MethodInvoker(CallRefresh));
           }
           else
                 this.Refresh();  
           }
           public void CallRefresh()      {
                  this.Refresh();
           }

Thanks,
Diganta Roy
Microsoft J# .NET Product Team.
--------------------
>Thread-Topic: Marine Biology Simulation w/J# 2005 Express
>thread-index: AcXyGP90rWTXHqHQRvuxiHlIswmO9g==
[quoted text clipped - 26 lines]
>
>What gives?

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.