Click here to Skip to main content
       

.NET Framework

 
AnswerRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberSimon_Whale19-Nov-12 4:04 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661319-Nov-12 5:37 
AnswerRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen19-Nov-12 6:04 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661319-Nov-12 23:54 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen20-Nov-12 1:53 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661320-Nov-12 4:36 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen20-Nov-12 5:33 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661320-Nov-12 6:23 
Here is the code (the code is in two files: one for Form1 and one for MyThread):
 
Imports System.Threading
 
Public Class Form1
  Dim MyNewThread As Thread
 
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'create the thread 
    MyNewThread = New Thread(AddressOf MyThread.MyThreadExecute)
    MyNewThread.Name = "NuovoThread"
    'start the thread
    MyNewThread.Start()   'no "Me" parameter
  End Sub
 
  Public Sub AggiornaLabel(ByVal What As String)
    If InvokeRequired Then
      Invoke(New Action(Of String)(AddressOf AggiornaLabel), New Object() {What})
      Return
    End If
 
    Label1.Text = What
  End Sub
 
End Class
 

Public Class MyThread
  Private Shared miii As Int32 = 0
 
  Public Shared Property iii() As Int32
    Get
      Return miii
    End Get
    Set(ByVal value As Int32)
      miii = value
    End Set
  End Property
 
  Public Shared Sub MyThreadExecute(ByVal Origin As Object)
  'Public Shared Sub MyThreadExecute()
    Dim OriginForm As Form1 = CType(Origin, Form1)
    'Dim OriginForm As Form1 = New Form1()
    Do
      iii = iii + 1
      OriginForm.AggiornaLabel(iii.ToString)
      Thread.Sleep(100)
    Loop
  End Sub
End Class
 
 
if I remove the "origin" parameter as in the commented lines in the code above the error disappears and I can run the application on the device but the label is not updated because the condition "If InvokeRequired Then" is alwais false (as it was in the first example I posted).
Perhaps I have not removed the "origin" parameter in a consistent manner (I have more then one doubt about the line "Dim OriginForm As Form1 = New Form1()"...)
 
About passing a parameter in an object when I start the thread, I can't do this because in the Compact Framework (not the full .NET) only the method Thread.Start() is supported, the method Thread.Start(Object) is not supported.
Perhaps this is another reason why the code doesnt work: the MyThreadExecute-method has no "connection" with Form1 and so in Form1 InvokeRequired is false.
 
ps: I thank you for your patience...
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen20-Nov-12 10:21 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661320-Nov-12 22:25 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen21-Nov-12 6:07 
QuestionBinding gridview from webservice using jquery Pinmembersaravanan2509218-Nov-12 21:41 
AnswerRe: Binding gridview from webservice using jquery PinmemberPhanindra26119-Nov-12 7:05 
QuestionNlog for .Net compact PinmemberTalSt17-Nov-12 20:24 
AnswerRe: Nlog for .Net compact PinmvpRichard MacCutchan17-Nov-12 22:43 
GeneralRe: Nlog for .Net compact PinmemberTalSt18-Nov-12 2:15 
GeneralRe: Nlog for .Net compact PinmvpRichard MacCutchan18-Nov-12 2:36 
GeneralRe: Nlog for .Net compact PinmemberTalSt18-Nov-12 2:55 
GeneralRe: Nlog for .Net compact PinmvpRichard MacCutchan18-Nov-12 3:06 
AnswerRe: Nlog for .Net compact Pinmemberjschell19-Nov-12 10:11 
News.NET projects in koramangala,bangalore Pinmemberraji.1138716-Nov-12 23:24 
News2013 final year IEEE projects Pinmemberraji.1138716-Nov-12 23:20 
QuestionWebsite Developemnt Pinmemberradha123 from Hyderabad15-Nov-12 2:39 
AnswerRe: Website Developemnt PinmvpRichard MacCutchan15-Nov-12 3:41 
GeneralRe: Website Developemnt PinprotectorPete O'Hanlon15-Nov-12 4:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 25 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid