PC Review


Reply
Thread Tools Rate Thread

threading and control.incoke problem

 
 
Hauer Wolfgang
Guest
Posts: n/a
 
      28th Dec 2004
Hi!

I have an baseclass in the full framework wich encapsulates threading.
Recently i have expanded it for throwing an event when the thread has
finished. Because the event runs on the calling thread, i make a
control.invoke(delegate). This runs fine in the full framework, but crashes
with an argument-exception in cf.
Has someone an idea what could be wrong?
Thanks-Danke Wolfgang
-------------------->
Imports System.Windows.Forms
Public MustInherit Class ThreadWrapperBase
Public ReadOnly Thread As System.Threading.Thread
Private bmDone As Boolean
Protected Event ThreadDone(ByVal Sender As Object)
Private omControl As Control
Delegate Sub ThreadDoneDelegate()
Private MyThreadDoneDelegate As ThreadDoneDelegate = New
ThreadDoneDelegate(AddressOf LocalThreadDone)

Public Property Control() As Control
Get
Return omControl
End Get
Set(ByVal Value As Control)
omControl = Value
End Set
End Property

Sub New()
Me.Thread = New System.threading.Thread(AddressOf RunThread)
End Sub

Sub New(ByVal InvokerControl As Control)
Me.New()
omControl = InvokerControl
End Sub

Overridable Sub Start()
Me.Thread.Start()
End Sub

Private Sub RunThread()
bmDone = False
OnStart()
bmDone = True
if Not omControl Is Nothing Then
omControl.Invoke(MyThreadDoneDelegate)
###############> Problem is here
###################################################################################
Else
LocalThreadDone()
End If
End Sub
ReadOnly Property Done() As Boolean
Get
Return bmDone
End Get
End Property
Private Sub LocalThreadDone()
RaiseEvent ThreadDone(Me)
End Sub
Protected MustOverride Sub OnStart()
End Class



 
Reply With Quote
 
 
 
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      28th Dec 2004
All Control.Invoke targets in CF must use EventHandler signature:
void Handler(object, EventArgs)

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Hauer Wolfgang" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi!
>
> I have an baseclass in the full framework wich encapsulates threading.
> Recently i have expanded it for throwing an event when the thread has
> finished. Because the event runs on the calling thread, i make a
> control.invoke(delegate). This runs fine in the full framework, but
> crashes with an argument-exception in cf.
> Has someone an idea what could be wrong?
> Thanks-Danke Wolfgang
> -------------------->
> Imports System.Windows.Forms
> Public MustInherit Class ThreadWrapperBase
> Public ReadOnly Thread As System.Threading.Thread
> Private bmDone As Boolean
> Protected Event ThreadDone(ByVal Sender As Object)
> Private omControl As Control
> Delegate Sub ThreadDoneDelegate()
> Private MyThreadDoneDelegate As ThreadDoneDelegate = New
> ThreadDoneDelegate(AddressOf LocalThreadDone)
>
> Public Property Control() As Control
> Get
> Return omControl
> End Get
> Set(ByVal Value As Control)
> omControl = Value
> End Set
> End Property
>
> Sub New()
> Me.Thread = New System.threading.Thread(AddressOf RunThread)
> End Sub
>
> Sub New(ByVal InvokerControl As Control)
> Me.New()
> omControl = InvokerControl
> End Sub
>
> Overridable Sub Start()
> Me.Thread.Start()
> End Sub
>
> Private Sub RunThread()
> bmDone = False
> OnStart()
> bmDone = True
> if Not omControl Is Nothing Then
> omControl.Invoke(MyThreadDoneDelegate)
> ###############> Problem is here
> ###################################################################################
> Else
> LocalThreadDone()
> End If
> End Sub
> ReadOnly Property Done() As Boolean
> Get
> Return bmDone
> End Get
> End Property
> Private Sub LocalThreadDone()
> RaiseEvent ThreadDone(Me)
> End Sub
> Protected MustOverride Sub OnStart()
> End Class
>
>
>



 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      28th Dec 2004
The limitations of the NETCF Control.Invoke along with workarounds are
described here:
http://www.danielmoth.com/Blog/2004/...d-full-fx.html

Since you are already wrapping thread usage and Invoke in a class I suggest
you use the BackgroundWorker instead:
http://www.danielmoth.com/Blog/2004/...for-cf-10.html

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Hauer Wolfgang" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi!
>
> I have an baseclass in the full framework wich encapsulates threading.
> Recently i have expanded it for throwing an event when the thread has
> finished. Because the event runs on the calling thread, i make a
> control.invoke(delegate). This runs fine in the full framework, but
> crashes with an argument-exception in cf.
> Has someone an idea what could be wrong?
> Thanks-Danke Wolfgang
> -------------------->
> Imports System.Windows.Forms
> Public MustInherit Class ThreadWrapperBase
> Public ReadOnly Thread As System.Threading.Thread
> Private bmDone As Boolean
> Protected Event ThreadDone(ByVal Sender As Object)
> Private omControl As Control
> Delegate Sub ThreadDoneDelegate()
> Private MyThreadDoneDelegate As ThreadDoneDelegate = New
> ThreadDoneDelegate(AddressOf LocalThreadDone)
>
> Public Property Control() As Control
> Get
> Return omControl
> End Get
> Set(ByVal Value As Control)
> omControl = Value
> End Set
> End Property
>
> Sub New()
> Me.Thread = New System.threading.Thread(AddressOf RunThread)
> End Sub
>
> Sub New(ByVal InvokerControl As Control)
> Me.New()
> omControl = InvokerControl
> End Sub
>
> Overridable Sub Start()
> Me.Thread.Start()
> End Sub
>
> Private Sub RunThread()
> bmDone = False
> OnStart()
> bmDone = True
> if Not omControl Is Nothing Then
> omControl.Invoke(MyThreadDoneDelegate)
> ###############> Problem is here
> ###################################################################################
> Else
> LocalThreadDone()
> End If
> End Sub
> ReadOnly Property Done() As Boolean
> Get
> Return bmDone
> End Get
> End Property
> Private Sub LocalThreadDone()
> RaiseEvent ThreadDone(Me)
> End Sub
> Protected MustOverride Sub OnStart()
> End Class
>
>
>



 
Reply With Quote
 
Hauer Wolfgang
Guest
Posts: n/a
 
      2nd Jan 2005
Tks, i think that will work

wolfgang

"Alex Feinman [MVP]" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> All Control.Invoke targets in CF must use EventHandler signature:
> void Handler(object, EventArgs)
>
> --
> Alex Feinman
> ---
> Visit http://www.opennetcf.org
> "Hauer Wolfgang" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi!
>>
>> I have an baseclass in the full framework wich encapsulates threading.
>> Recently i have expanded it for throwing an event when the thread has
>> finished. Because the event runs on the calling thread, i make a
>> control.invoke(delegate). This runs fine in the full framework, but
>> crashes with an argument-exception in cf.
>> Has someone an idea what could be wrong?
>> Thanks-Danke Wolfgang
>> -------------------->
>> Imports System.Windows.Forms
>> Public MustInherit Class ThreadWrapperBase
>> Public ReadOnly Thread As System.Threading.Thread
>> Private bmDone As Boolean
>> Protected Event ThreadDone(ByVal Sender As Object)
>> Private omControl As Control
>> Delegate Sub ThreadDoneDelegate()
>> Private MyThreadDoneDelegate As ThreadDoneDelegate = New
>> ThreadDoneDelegate(AddressOf LocalThreadDone)
>>
>> Public Property Control() As Control
>> Get
>> Return omControl
>> End Get
>> Set(ByVal Value As Control)
>> omControl = Value
>> End Set
>> End Property
>>
>> Sub New()
>> Me.Thread = New System.threading.Thread(AddressOf RunThread)
>> End Sub
>>
>> Sub New(ByVal InvokerControl As Control)
>> Me.New()
>> omControl = InvokerControl
>> End Sub
>>
>> Overridable Sub Start()
>> Me.Thread.Start()
>> End Sub
>>
>> Private Sub RunThread()
>> bmDone = False
>> OnStart()
>> bmDone = True
>> if Not omControl Is Nothing Then
>> omControl.Invoke(MyThreadDoneDelegate)
>> ###############> Problem is here
>> ###################################################################################
>> Else
>> LocalThreadDone()
>> End If
>> End Sub
>> ReadOnly Property Done() As Boolean
>> Get
>> Return bmDone
>> End Get
>> End Property
>> Private Sub LocalThreadDone()
>> RaiseEvent ThreadDone(Me)
>> End Sub
>> Protected MustOverride Sub OnStart()
>> End Class
>>
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I do this (threading and UI control update) Just_a_fan@home.net Microsoft VB .NET 2 21st Apr 2008 12:25 PM
User Control and Threading Help teillon Microsoft VB .NET 3 3rd Mar 2006 11:17 AM
Help with threading/control.invoke Rich Microsoft Dot NET Compact Framework 3 18th Jan 2005 05:29 PM
Using threading with a datagrid control Marco Microsoft VB .NET 2 2nd Sep 2004 04:42 PM
Multi-Threading GUI control..problem. GoodMorningSky Microsoft Dot NET Framework Forms 1 24th Aug 2004 04:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:32 PM.