Click here to Skip to main content
       

.NET Framework

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
AnswerRe: estoy tratando de compilar un archivo.mex a .netmemberEddy Vluggen19 Nov '12 - 11:09 
..and now again, in English Smile | :)
 
Just use a translator. I don't care how bad it sounds, can't be worse than my average post - a half decent English post still reaches a wider audience than a Spanish one.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: estoy tratando de compilar un archivo.mex a .netmemberIdeasPravinh23 Nov '12 - 23:47 
test
Pravin the Best

AnswerRe: estoy tratando de compilar un archivo.mex a .netmemberBernhard Hiller19 Nov '12 - 22:35 
When I look into C:\Windows\Microsoft.NET\Framework\v3.0, I do not see a csc.exe. But there is one in C:\Windows\Microsoft.NET\Framework\v2.0.50727.
GeneralRe: estoy tratando de compilar un archivo.mex a .netmemberyeyomax20 Nov '12 - 5:25 
I alter the deployments, .. settings, .. . net .. 2.0 this worked
GeneralRe: estoy tratando de compilar un archivo.mex a .netmvpDave Kreskowiak20 Nov '12 - 6:11 
You won't find a csc.exe under the .NET 3.0, 3.5 or 4.5 folders as these versions are just extensions on top of the .NET 2.0 and .NET 4.0 versions, which will have csc.exe.

Question[VB.NET 2008] Change form from separate thread (Windows CE)memberMember 949661319 Nov '12 - 2: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)memberSimon_Whale19 Nov '12 - 3:04 
Does it give an exception? not work as expected?
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE)membersteve_949661319 Nov '12 - 4:37 
No, it doesn't give an exception, just it does nothing.
The first example, all the code in the Form1 clas, works as expected.
AnswerRe: [VB.NET 2008] Change form from separate thread (Windows CE)memberEddy Vluggen19 Nov '12 - 5:04 
Member 9496613 wrote:
Where did I go wrong?

Can anyone give me a tip?

Two; don't use global variables to pass state, and set MSDN[^] as your homepage. Try something similar to the code below;
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(Me)
    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)
        Dim OriginForm As Form1 = CType(Origin, Form1)
        Do
            iii = iii + 1
            OriginForm.AggiornaLabel(iii.ToString)
            Thread.Sleep(100)
        Loop
    End Sub
End Class
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE)membersteve_949661319 Nov '12 - 22:54 
Thanks for your answer.
 
Your example works if i create a project for a desktop pc, but my project has to run in a Windows CE 5.0 environment (Compact Framework 3.5) and it doesn't work.
I get two errors:
 
1) MyNewThread.Start(Me): "too many arguments for 'Public Sub Start()'"
2) Method 'Public Shared Sub MyThreadExecute(Origin As Object)' does not have a signature compatible with delegate 'Delegate Sub ThreadStart()'
 
1) the method Start(Object) is not supported in Compact Framework so I have to call MyNewThread.Start()
 
For the second error, I'm searching through MSDN... but I don't understand well, I think I have to modify MyThreadExecute(...) because I can't modify ThreadStart()... now I try, but if you already know the answer...
 
About the use of global variables, is it such a bad thing?
The real application is more complex of this example, the function executed by the thread will communicate with a PLC via ethernet and will read a lot of data (and write some) and then, at the end of each loop, it will call a function to visualize new data in different "pages" (I use UserControl objects) in the application. My idea is to use a class in order to collect all of these data and make them available inside and outside the thread. What do you think about this?
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE)memberEddy Vluggen20 Nov '12 - 0:53 
steve_9496613 wrote:
1) the method Start(Object) is not supported in Compact Framework so I have to call MyNewThread.Start()

For the second error, I'm searching through MSDN...

The delegate is probably missing one of the parameters used.
 
steve_9496613 wrote:
About the use of global variables, is it such a bad thing?

Usuallly done to keep things "simple", usually makes things more complicated. See, you'll need access to the form (from the thread), to invoke one of it's members.
 
Alternatively, you might want to check out locking.
 
steve_9496613 wrote:
The real application is more complex of this example, the function executed by the thread will communicate with a PLC via ethernet and will read a lot of data (and write some) and then, at the end of each loop, it will call a function to visualize new data in different "pages" (I use UserControl objects) in the application. My idea is to use a class in order to collect all of these data and make them available inside and outside the thread. What do you think about this

Sounds feasible. Remember to only update the visible stuff, resources will probably be scarce Smile | :)
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE)membersteve_949661320 Nov '12 - 3:36 
I'm not able to solve the second error (Method 'Public Shared Sub MyThreadExecute(Origin As Object)' does not have a signature compatible with delegate 'Delegate Sub ThreadStart()').
When I create the thread with the instruction:
 
MyNewThread = New Thread(AddressOf MyThread.MyThreadExecute)
 
I can't add any other parameter, or I don't know how.
 
Searching the help I found that the delegate ThreadStart() is called automatically when I call "New Thread(AddressOf ...)" so how can I modify its parameters?
 
I really don't know what to do...
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE)memberEddy Vluggen20 Nov '12 - 4:33 
Can you post the code in it's current state?
 
Guess it'll work if you remove the "origin" parameter that I added there Smile | :)
 
steve_9496613 wrote:
Searching the help I found that the delegate ThreadStart() is called automatically when I call "New Thread(AddressOf ...)" so how can I modify its parameters?

One can pass in an object when the thread is started;
MyNewThread.Start(Me)
At that point, "Me" would be the form. The start-method then executes the MyThreadExecute-method, where we have to cast it back to it's original type.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE)membersteve_949661320 Nov '12 - 5: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)memberEddy Vluggen20 Nov '12 - 9:21 
steve_9496613 wrote:
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.

Aw, darn. Without that, it's not possible to pass the form as an argument.
 
Since AggiornaLabel is a method of the form (as should be), you'd need to have a reference to the form in order to invoke it. An ugly bypass would be to use a "shared" member, aka a static method. Works similar to the shared integer called 'iii'.
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"
        MyThread.ThatForm = Me
        'start the thread
        MyNewThread.Start()
    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 ThatForm As Form1
 
    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
            ThatForm.AggiornaLabel(iii.ToString)
            Thread.Sleep(100)
        Loop
    End Sub
End Class
That's abusing things a bit; a class that's never instantiated would be a module, eliminating the need to declare each member being 'shared';
Module MyThread
    Private miii As Int32 = 0
    Public ThatForm As Form1
 
    Public Property iii() As Int32
        Get
            Return miii
        End Get
        Set(ByVal value As Int32)
            miii = value
        End Set
    End Property
 
    Public Sub MyThreadExecute()
        Do
            iii = iii + 1
            ThatForm.AggiornaLabel(iii.ToString)
            Thread.Sleep(100)
        Loop
    End Sub
End Module
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE)membersteve_949661320 Nov '12 - 21:25 
Yessss! It works! Thumbs Up | :thumbsup:
 
Both with the class than with the module.
In my project I have used a class but, if it is a cleaner way, I can still use a module, the project is not so advanced so the changes will not be too painful.
 
Thank you very much Eddy, your help has been precious!
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE)memberEddy Vluggen21 Nov '12 - 5:07 
You're welcome Smile | :)
QuestionBinding gridview from webservice using jquerymembersaravanan2509218 Nov '12 - 20:41 
Hi friends,
Now I want to bind gridview from webservice using jquery,ajax or javascript..
How can i achive that..
AnswerRe: Binding gridview from webservice using jquerymemberPhanindra26119 Nov '12 - 6:05 
The solution to your problem comes in three steps
1. Write [WebMethod] (service) to return data from the datatable. But before returning it to your ajax method call convert it to an array. This is because javascript does not understand things such as datatable,dataset,datarow etc...
 
2. In your aspx page header write an ajax call which should look something like this:-
$(document).ready(function() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/BindDatatable",
data: "{}",
dataType: "json",
success: function(data) {
for (var i = 0; i < data.d.length; i++) {
$("#gvDetails").append("<tr><td>" + data.d[i].UserId + "</td><td>" + data.d[i].UserName + "</td><td>" + data.d[i].Location + "</td></tr>");
}
},
error: function(result) {
alert("Error");
}
});
});
inside the script tags. UserName,UserId,Location are column names from the database.
3. Bind a dummy datatable to your gridview. It should look something like this:
private void BindColumnToGridview()
{
DataTable dt = new DataTable();
dt.Columns.Add("UserId");
dt.Columns.Add("UserName");
dt.Columns.Add("Location");
dt.Rows.Add();
gvDetails.DataSource = dt;
gvDetails.DataBind();
gvDetails.Rows[0].Visible = false;
}
 
this is done so that correct data is mapped to the correct columns in gridview.
All the best.
QuestionNlog for .Net compactmemberTalSt17 Nov '12 - 19:24 
Hello
 
Do you know of any example for Nlog for .Net compact 3.5?
 
Any help how to start working with Nlog for .Net compact?
 
Thanks!
AnswerRe: Nlog for .Net compactmvpRichard MacCutchan17 Nov '12 - 21:43 
TalSt wrote:
Do you know of any example for Nlog for .Net compact 3.5?
Try here[^].
One of these days I'm going to think of a really clever signature.

GeneralRe: Nlog for .Net compactmemberTalSt18 Nov '12 - 1:15 
Thanks, but I need specific information Wink | ;)
GeneralRe: Nlog for .Net compactmvpRichard MacCutchan18 Nov '12 - 1:36 
Then you need to post a specific question; we cannot guess what your problem may be.
One of these days I'm going to think of a really clever signature.

GeneralRe: Nlog for .Net compactmemberTalSt18 Nov '12 - 1:55 
I am looking for logging code for .Net compact, for example writing to log file, msgbox amd so.
 
thanks!
GeneralRe: Nlog for .Net compactmvpRichard MacCutchan18 Nov '12 - 2:06 
Did you try a Google search[^]?
One of these days I'm going to think of a really clever signature.

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


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid