Click here to Skip to main content
11,479,034 members (61,443 online)

.NET Framework

 
GeneralRe: programming Pin
eeshwr23-Nov-12 6:38
membereeshwr23-Nov-12 6:38 
Questioncalculate average inside my ssrs 2008 Pin
menacy22-Nov-12 11:09
membermenacy22-Nov-12 11:09 
AnswerRe: calculate average inside my ssrs 2008 Pin
Richard MacCutchan23-Nov-12 0:35
mvpRichard MacCutchan23-Nov-12 0:35 
QuestionString compression Pin
Blikkies19-Nov-12 22:03
memberBlikkies19-Nov-12 22:03 
AnswerRe: String compression Pin
n.podbielski19-Nov-12 22:15
membern.podbielski19-Nov-12 22:15 
GeneralRe: String compression Pin
Blikkies19-Nov-12 22:19
memberBlikkies19-Nov-12 22:19 
JokeRe: String compression Pin
n.podbielski19-Nov-12 22:22
membern.podbielski19-Nov-12 22:22 
Questionestoy tratando de compilar un archivo.mex a .net [modified] Pin
yeyomax19-Nov-12 10:33
memberyeyomax19-Nov-12 10:33 
AnswerRe: estoy tratando de compilar un archivo.mex a .net Pin
Eddy Vluggen19-Nov-12 12:09
memberEddy Vluggen19-Nov-12 12:09 
GeneralRe: estoy tratando de compilar un archivo.mex a .net Pin
IdeasPravinh24-Nov-12 0:47
memberIdeasPravinh24-Nov-12 0:47 
AnswerRe: estoy tratando de compilar un archivo.mex a .net Pin
Bernhard Hiller19-Nov-12 23:35
memberBernhard Hiller19-Nov-12 23:35 
GeneralRe: estoy tratando de compilar un archivo.mex a .net Pin
yeyomax20-Nov-12 6:25
memberyeyomax20-Nov-12 6:25 
GeneralRe: estoy tratando de compilar un archivo.mex a .net Pin
Dave Kreskowiak20-Nov-12 7:11
mvpDave Kreskowiak20-Nov-12 7:11 
Question[VB.NET 2008] Change form from separate thread (Windows CE) Pin
Member 949661319-Nov-12 3:51
memberMember 949661319-Nov-12 3:51 
Hello everybody,
I have a problem about the modification of fields (such as textbox, label, acc) of a form from another thread.
I state that I am not an expert on Visual Studio 2008 and, unfortunately, even on VB.NET but I have to use these tools to write an application that runs on a device with Windows CE 5.0.
In another forum I've already found a post about it and I followed the solution proposed.
Everything works if I write all the code in the class of my form (Form1), I mean in the Form1 there is a button that starts a thread that increments by 1 a variable declared in Form1, and then calls a "Sub AggLab()", always in Form1, that updates the contents of a label (in Form1) with the increased value of the variable:

Imports System.Threading
 
Public Class Form1
  Dim MyNewThread As Thread
  Dim tmp As Int32 = 0
 
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'create the thread
    MyNewThread = New Thread(AddressOf SubDelThread)
    MyNewThread.Name = "NuovoThread"
    'start the thread
    MyNewThread.Start()
  End Sub
 

  Private Sub SubDelThread()
    Do
      tmp = tmp + 1
      AggLab()
      Thread.Sleep(1000)
    Loop
  End Sub
 
  Private Delegate Sub AggLabDel()
  Private Sub AggLab()
 
    If Me.InvokeRequired Then
      Me.BeginInvoke(New AggLabDel(AddressOf AggLab))
      Return
    End If
 
    Label1.Text = tmp.ToString
 
  End Sub
 
End Class

But if the function executed within the thread is in a different class/file it does not work anymore:

'file Form1.vb

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()
  End Sub
 
  Private Delegate Sub AggiornaLabelDelegate()
  Public Sub AggiornaLabel()
 
    If Me.InvokeRequired Then
      Me.BeginInvoke(New AggiornaLabelDelegate(AddressOf AggiornaLabel))
      Return
    End If
 
    Label1.Text = MyThread.iii.ToString
 
  End Sub

'file MyThread.vb

Imports System.Threading
 
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()
    Do
      iii = iii + 1
      Form1.AggiornaLabel()
      Thread.Sleep(1000)
    Loop
  End Sub
 
End Class

What I check with debugging is that in this case "Me.InvokeRequired" is always false.

Where did I go wrong?
Can anyone give me a tip?

Thanks in advance.
AnswerRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
Simon_Whale19-Nov-12 4:04
memberSimon_Whale19-Nov-12 4:04 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
steve_949661319-Nov-12 5:37
membersteve_949661319-Nov-12 5:37 
AnswerRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
Eddy Vluggen19-Nov-12 6:04
memberEddy Vluggen19-Nov-12 6:04 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
steve_949661319-Nov-12 23:54
membersteve_949661319-Nov-12 23:54 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
Eddy Vluggen20-Nov-12 1:53
memberEddy Vluggen20-Nov-12 1:53 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
steve_949661320-Nov-12 4:36
membersteve_949661320-Nov-12 4:36 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
Eddy Vluggen20-Nov-12 5:33
memberEddy Vluggen20-Nov-12 5:33 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
steve_949661320-Nov-12 6:23
membersteve_949661320-Nov-12 6:23 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
Eddy Vluggen20-Nov-12 10:21
memberEddy Vluggen20-Nov-12 10:21 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
steve_949661320-Nov-12 22:25
membersteve_949661320-Nov-12 22:25 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pin
Eddy Vluggen21-Nov-12 6:07
memberEddy Vluggen21-Nov-12 6:07 
QuestionBinding gridview from webservice using jquery Pin
saravanan2509218-Nov-12 21:41
membersaravanan2509218-Nov-12 21:41 
AnswerRe: Binding gridview from webservice using jquery Pin
Phanindra26119-Nov-12 7:05
memberPhanindra26119-Nov-12 7:05 
QuestionNlog for .Net compact Pin
TalSt17-Nov-12 20:24
memberTalSt17-Nov-12 20:24 
AnswerRe: Nlog for .Net compact Pin
Richard MacCutchan17-Nov-12 22:43
mvpRichard MacCutchan17-Nov-12 22:43 
GeneralRe: Nlog for .Net compact Pin
TalSt18-Nov-12 2:15
memberTalSt18-Nov-12 2:15 
GeneralRe: Nlog for .Net compact Pin
Richard MacCutchan18-Nov-12 2:36
mvpRichard MacCutchan18-Nov-12 2:36 
GeneralRe: Nlog for .Net compact Pin
TalSt18-Nov-12 2:55
memberTalSt18-Nov-12 2:55 
GeneralRe: Nlog for .Net compact Pin
Richard MacCutchan18-Nov-12 3:06
mvpRichard MacCutchan18-Nov-12 3:06 
AnswerRe: Nlog for .Net compact Pin
jschell19-Nov-12 10:11
memberjschell19-Nov-12 10:11 
GeneralRe: Nlog for .Net compact Pin
TalSt28-Jan-15 20:02
memberTalSt28-Jan-15 20:02 
News.NET projects in koramangala,bangalore Pin
raji.1138716-Nov-12 23:24
memberraji.1138716-Nov-12 23:24 
News2013 final year IEEE projects Pin
raji.1138716-Nov-12 23:20
memberraji.1138716-Nov-12 23:20 
QuestionWebsite Developemnt Pin
radha123 from Hyderabad15-Nov-12 2:39
memberradha123 from Hyderabad15-Nov-12 2:39 
AnswerRe: Website Developemnt Pin
Richard MacCutchan15-Nov-12 3:41
mvpRichard MacCutchan15-Nov-12 3:41 
GeneralRe: Website Developemnt Pin
Pete O'Hanlon15-Nov-12 4:00
protectorPete O'Hanlon15-Nov-12 4:00 
GeneralRe: Website Developemnt Pin
Richard MacCutchan15-Nov-12 5:12
mvpRichard MacCutchan15-Nov-12 5:12 
GeneralRe: Website Developemnt Pin
Paul Conrad15-Nov-12 11:37
memberPaul Conrad15-Nov-12 11:37 
AnswerRe: Website Developemnt Pin
jschell15-Nov-12 9:07
memberjschell15-Nov-12 9:07 
GeneralRe: Website Developemnt Pin
dojohansen20-Nov-12 7:02
memberdojohansen20-Nov-12 7:02 
AnswerRe: Website Developemnt Pin
Zaf Khan19-Nov-12 18:24
memberZaf Khan19-Nov-12 18:24 
Questionis Windows-8 can run Webservice that work with FrameWork3.5? Pin
goldsoft11-Nov-12 10:08
membergoldsoft11-Nov-12 10:08 
AnswerRe: is Windows-8 can run Webservice that work with FrameWork3.5? Pin
n.podbielski13-Nov-12 22:08
membern.podbielski13-Nov-12 22:08 
QuestionSpeech Recognition (System.speech) Pin
saurabh orange vyas10-Nov-12 1:10
membersaurabh orange vyas10-Nov-12 1:10 
AnswerRe: Speech Recognition (System.speech) Pin
Eddy Vluggen10-Nov-12 8:19
memberEddy Vluggen10-Nov-12 8:19 
GeneralRe: Speech Recognition (System.speech) Pin
saurabh orange vyas10-Nov-12 22:15
membersaurabh orange vyas10-Nov-12 22:15 

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.150520.1 | Last Updated 21 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid