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 / Visual Studio.NET / General / July 2004

Tip: Looking for answers? Try searching our database.

VS2005 Express : Debug problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lei Jiang - 30 Jun 2004 06:31 GMT
When my program run in debug mode, some exceptions thrown :

Illegal cross-thread operation: Control '' accessed from a thread other than
the thread it was created on.\r\nStack trace where the illegal operation
occurred was:\r\n\r\n\tat System.Windows.Forms.Control.get_Handle()\r\n\tat
System.Windows.Forms.Control.SetBoundsCore(Int32, Int32, Int32, Int32,
BoundsSpecified)\r\n\tat System.Windows.Forms.Form.SetBoundsCore(Int32,
Int32, Int32, Int32, BoundsSpecified)\r\n\tat
System.Windows.Forms.Control.SetBounds(Int32, Int32, Int32, Int32)\r\n\tat
Syncfusion.Windows.Forms.Tools.WrapperForm.HandleAnimationTimer(Object,
ElapsedEventArgs)\r\n\tat
System.Timers.Timer.MyTimerCallback(Object)\r\n\tat
System.Threading._TimerCallback.TimerCallback_Context(Object)\r\n\tat
System.Threading.ExecutionContext.Run(ExecutionContext, ContextCallback,
Object, StackCrawlMark&)\r\n\tat
System.Threading._TimerCallback.TimerCallback(Object)\r\n\"

after I ignore this exception and continue the program, another exception is
thrown :

The channel 'http' is already registered.

I use remoting in my progrem, this exception is thrown during the remoting
setup.

However, when I run my program standalone(out side vs.net), there is no
problem. And these exception is not occured when I debug my progrem under
VS.NET 2003.
Steve McLellan - 30 Jun 2004 10:19 GMT
The first exception is saying that you're accing a control object from a
thread other than that it was created in. VS 2003 doesn't give this warning,
unfortunately, you just get odd behaviour. Don't know what the second one's
about. Post some minimal code that reproduces the behaviour.

Steve

> When my program run in debug mode, some exceptions thrown :
>
[quoted text clipped - 24 lines]
> problem. And these exception is not occured when I debug my progrem under
> VS.NET 2003.
Jim Di Griz - 04 Jul 2004 14:32 GMT
Situation:
A worker thread calls a method in the UI thread (or raises an event in
the UI thread)

In 2003 it was possible to update UI controls directly from the called
methods.

2005 throws an error:

Illegal cross-thread operation: Control 'StatusBarPanel1' accessed
from a thread other than the thread it was created on.

Solution:

Public Sub ThreadFeedback(ByVal sender As Object, ByVal e As
ThreadEventArgs) Implements IAsynchThread.ThreadFeedback
   'Tell calling worker thread whether to cancel operation
   e.Cancel = _Cancel
   'Call UI thread asynchronously (and thus thread save)
   Dim pList As Object() = {sender, e}
   Me.BeginInvoke(New System.EventHandler(AddressOf UpdateUI), pList)
   Application.DoEvents()
End Sub

Private Sub UpdateUI(ByVal sender As Object, ByVal e As
System.EventArgs)
   'Do all the UI thread relevant stuff here
   'e.g. update StatusBar panel text etc.
   Dim ef As ThreadEventArgs = CType(e, ThreadEventArgs)
   StatusBarPanel1.Text = ef.Text
End Sub

'Remarks:
'IAsynchThread is an Interface of my own
'ThreadEventArgs is a Class of my own
'_Cancel is a UI module level variable that is set to True
'when the user clicks on the Cancel button.

Reason:
The UI controls are not thread safe. Previous versions of .Net would
allow these thread-unsafe to be made, but they will cause weird things
to happen (often resulting in the application just disappearing)
eventually. .Net 2 detects these bad cross-thread calls, and raises an
exception.

When in another thread, you should invoke all UI control methods using
BeginInvoke and EndInvoke rather than directly.

> When my program run in debug mode, some exceptions thrown :
>
[quoted text clipped - 24 lines]
> problem. And these exception is not occured when I debug my progrem under
> VS.NET 2003.
Lei Jiang - 05 Jul 2004 02:28 GMT
Thank you for your explanation. But why I run the application standalone, it
works ok? The exception is only thrown in debugger.

> Situation:
> A worker thread calls a method in the UI thread (or raises an event in
[quoted text clipped - 72 lines]
> > problem. And these exception is not occured when I debug my progrem under
> > VS.NET 2003.

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.