Compact framerk, multithreading Invoke problem

C

Chris Tacke, eMVP

The CF 1.0 only supports synchronous Invoke, and only with delegates that
are of the type EventHandler. That's the only option.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
P

Piotrek \Alchemik\

Daniel said:
Asynchronous invocation (BeginInvoke) or passing parameters (using
anything other than EventHandler) is not supported in CF 1.0:
http://www.danielmoth.com/Blog/2004/10/invoke-cf-and-full-fx.html

Great. I found a solutions in your blog how to pass a argument to through
invoke, but it's written in VB and i have no idea what is this:

Private Sub UpdateBox(ByVal sender As Object, ByVal e As EventArgs)
Dim o As Object SyncLock mDataQue.SyncRoot
If mDataQue.Count > 0 Then
o = mDataQue.Dequeue()
End If End SyncLock
' TODO use o
' cast o to your object/structure and
' use it to update the GUI
End Sub

Maybe somebody has a solution in C, C++, C#?
 
D

Daniel Moth

Which bit do you have difficulty with?

HINT: You must learn to at least read VB.NET
HINT 2: There are many online converters (and I don't mean other people :)

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


Piotrek "Alchemik" said:
Daniel said:
Asynchronous invocation (BeginInvoke) or passing parameters (using
anything other than EventHandler) is not supported in CF 1.0:
http://www.danielmoth.com/Blog/2004/10/invoke-cf-and-full-fx.html

Great. I found a solutions in your blog how to pass a argument to through
invoke, but it's written in VB and i have no idea what is this:

Private Sub UpdateBox(ByVal sender As Object, ByVal e As EventArgs) Dim o
As Object SyncLock mDataQue.SyncRoot If mDataQue.Count > 0 Then o =
mDataQue.Dequeue() End If End SyncLock ' TODO use o ' cast o to your
object/structure and
' use it to update the GUI
End Sub

Maybe somebody has a solution in C, C++, C#?
--
Piotrek "Alchemik" gg:183441
kilobyte[at]tlen[dot]pl
/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\/o|o\
"I am not in this world to live up to other people's expectations, nor
do I feel that the world must live up to mine." /Fritz Perls
 
P

Piotrek \Alchemik\

Daniel said:
Which bit do you have difficulty with?

HINT: You must learn to at least read VB.NET
HINT 2: There are many online converters (and I don't mean other people :)

Cheers
Daniel

Ok i found one, i think i'll try this later this evening.
Thank u.
 
P

Piotrek \Alchemik\

Daniel Moth wrote:
I made one small project with the solution i found and it looks like:
namespace Przyklad
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private Thread t1;
private ThreadStart starter1;
private System.Windows.Forms.Button button1;
public Linia ln;

public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
#endregion
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
starter1 = new ThreadStart(akcja);
t1 = new Thread(starter1);
t1.Start();
}

private void akcja()
{
ln.a="zmiana";
this.Invoke(new EventHandler(Zmiana));
Console.WriteLine(ln.a);
}

private void Zmiana (Object o, EventArgs e)
{
this.label1.Text = ln.a;
}
}


public class Linia
{
public String a;

Linia()
{
a="cos";
}
}
}

And the problem is that is not working. Maybe i'm doing something wrong?
Debugger told me that the problem is with line
this.label1.Text = ln.a;

If anybody could help me i'd be greatfull
Thanks in advance
 
D

Daniel Moth

It would help if you said what the error is rather than just "there is a
problem"... anyway...

I don't see where you create the object... maybe you should change the
declaration line to:
public Linia ln = new Linia();

Also you'll have to make the constructor of Linia public:
public Linia() {

Cheers
Daniel
 
P

Piotrek \Alchemik\

Daniel said:
It would help if you said what the error is rather than just "there is a
problem"... anyway...

I don't see where you create the object... maybe you should change the
declaration line to:
public Linia ln = new Linia();

Also you'll have to make the constructor of Linia public:
public Linia() {

Yes, indeed in this case it works perfect, but in my more complicated example i
have the same problem wharever i create that public or not. I pass elements to
invoke function, maybe there is somethin wrong with onpaint function from the
line class?

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (xLeft <= xRight)
{
Left = xLeft;
}
else
{
Left = xRight;
}
if (yLeft <= yRight)
{
Top = yLeft;
}
else
{
Top = yRight;
}
SolidBrush brush = new SolidBrush(this.Parent.BackColor);
e.Graphics.FillRectangle(brush, 0, 0, this.Width, this.Height);
Pen pen = new Pen(_color);
if (xLeft < xRight & yLeft < yRight)
{
e.Graphics.DrawLine(pen, 0, 0, this.Width, this.Height);
}
else if (xLeft > xRight & yLeft < yRight)
{
e.Graphics.DrawLine(pen, this.Width, 0, 0, this.Height);
}
else if (xLeft > xRight & yLeft > yRight)
{
e.Graphics.DrawLine(pen, this.Width, this.Height, 0, 0);
}
else if (xLeft < xRight & yLeft > yRight)
{
e.Graphics.DrawLine(pen, 0, this.Height, this.Width, 0);
}
}

And when i'm debugging my program stopped with
An unhandled exception of type 'System.ArgumentException' occurred in
System.Windows.Forms.dll

Additional information: ArgumentException when i'm trying to add my ln to
Controls. I have no other idea what else?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top