Re: [Mono-docs-list] Adding a link toStudentProjectsinContributingand ThreadsBeginnersGuide

2007-03-15 Thread Luciano _
Thanks a lot for the suggestions:
I reformatted the code with Coding Guidelines in my mind :)

I split up the *Passing parameters to threads* article in 2 sections, .NET 
1.0 (which i already did it in my previous post) and i add a new one .NET 
2.0 with the proper way to do this in .NET 2.0.
Concerning to callback example an explanation, this is the way that i did it 
in my code :) so, this is the way that i now how to do this, but i will read 
about BeginInvoke and EndInvoke and i will add this example too. I leave the 
Gtk stuff too :)

Thanks again for suggestion. I will be writting articles from now on with 
the common problems that i was having in my develpoment process, any 
suggestion will be really appreciated.

Luciano



>From: Valentin Sawadski <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: "Luciano _" <[EMAIL PROTECTED]>
>CC: mono-docs-list@lists.ximian.com
>Subject: Re: [Mono-docs-list] Adding a link 
>toStudentProjectsinContributingand ThreadsBeginnersGuide
>Date: Thu, 15 Mar 2007 16:58:23 +0100
>MIME-Version: 1.0
>Received: from lists.ximian.com ([130.57.169.22]) by 
>bay0-mc2-f4.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Thu, 15 
>Mar 2007 08:57:19 -0700
>Received: from galactus.ximian.com (localhost.localdomain [127.0.0.1])by 
>lists.ximian.com (Postfix) with ESMTP id A11CB1CFC18;Thu, 15 Mar 2007 
>13:37:07 -0400 (EDT)
>Received: from herald.ximian.com (frontgate.ximian.com [130.57.169.19])by 
>lists.ximian.com (Postfix) with ESMTP id 733531CFB8Bfor 
>;Thu, 15 Mar 2007 13:37:05 -0400 (EDT)
>Received: by herald.ximian.com (Postfix, from userid 2601)id 16661700B9; 
>Thu, 15 Mar 2007 10:57:17 -0500 (EST)
>Received: from mail.gmx.net (mail.gmx.net [213.165.64.20])by 
>herald.ximian.com (Postfix) with SMTP id EE8AF700B7for 
>;Thu, 15 Mar 2007 10:57:13 -0500 (EST)
>Received: (qmail invoked by alias); 15 Mar 2007 15:57:12 -
>X-Message-Info: 
>LsUYwwHHNt2+ldJmBX4L0Xte/npGRrKPVjXqJpQTzuDdZbVV4S146IFPkDBjfgPY
>X-Original-To: mono-docs-list@lists.ximian.com
>Delivered-To: mono-docs-list@lists.ximian.com
>X-Provags-ID: 
>V01U2FsdGVkX1/ETd0Wl7zEcdo/htpKp5lfI1B5Z9pJY75+UhAqgIlyrhJrJNbWleGu
>User-Agent: KMail/1.9.5
>References: <[EMAIL PROTECTED]>
>X-Y-GMX-Trusted: 0
>X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on 
>frontgate.ximian.com
>X-Spam-Level: *
>X-Spam-Status: No, score=1.8 required=5.0 
>tests=MY_OBFUJ,MY_OBFUT,SPF_HELO_PASS,SPF_PASS version=3.0.3
>X-BeenThere: mono-docs-list@lists.ximian.com
>X-Mailman-Version: 2.1.8
>Precedence: list
>List-Id: "Documentation for Mono." 
>List-Unsubscribe: 
>,PROTECTED]>
>List-Archive: 
>List-Post: 
>List-Help: 
>List-Subscribe: 
>,PROTECTED]>
>Errors-To: [EMAIL PROTECTED]
>Return-Path: [EMAIL PROTECTED]
>X-OriginalArrivalTime: 15 Mar 2007 15:57:19.0884 (UTC) 
>FILETIME=[9CAE7CC0:01C7671A]
>
>Hi Luciano,
>
>first, thanks for taking to time to contribute to mono. :-)
>
>Now, I've taken a look at your submissions and would suggest, that you 
>should
>leave out the GTK stuff. Since this Guide shall only contain information
>which can be used in any context. (As I wrote on the top of the article).
>Instead you could try how to make your own threaded library responsive by
>saying how this can be achieved and how that library should then be used.
>
>In addition I would encourage you to rewrite your first example to use the
>ParameterizedThreadStart Delegate
>(http://msdn2.microsoft.com/en-us/library/system.threading.parameterizedthreadstart.aspx),
>since this is the standard way for invoking threads with parameters in the
>2.0 version of .NET.
>
>The callback example looks quite good. But If you like you could show how 
>to
>use delegates to execute methods synchronously with DynamicInvoke or 
>"normal"
>invocation wit paranthesis and asynchronously by using the BeginInvoke and
>EndInvoke methods as well as wheres the difference between them (which 
>method
>is being excecuted on what thread, which thread has to wait till the 
>delegate
>executes,...)
>
>But, keep up the good work and please mind the coding guidelines for mono
>(http://mono-project.com/Coding_Guidelines) when submitting code samples.
>
>Kind Regards,
>Valentin S.
>
>On Thursday 15 March 2007 13:07, you wrote:
> > I get no password or even write access :)
> > So, i attach a text file with the info to add to this article.
> >
> > Bye
> > Luciano
> >
> > >From: Miguel de Icaza <[EMAIL PROTECTED]>
> > >To: Luciano _ <[EMAIL PROTECTED]>
> > >CC: [EMAIL PROTECTED], mono-docs-list@lists.ximian.com
> > >Subject: Re: [Mono-docs-list] Adding a link to
> > >StudentProjectsinContributingand ThreadsBeginnersGuide
> > >Date: Tue, 13 Mar 2007 12:45:30 -0400
> > >MIME-Version: 1.0
> > >Received: from erandi.dom ([130.57

Re: [Mono-docs-list] Adding a link to StudentProjectsinContributingand ThreadsBeginnersGuide

2007-03-15 Thread Valentin Sawadski
Hi Luciano,

first, thanks for taking to time to contribute to mono. :-)

Now, I've taken a look at your submissions and would suggest, that you should 
leave out the GTK stuff. Since this Guide shall only contain information 
which can be used in any context. (As I wrote on the top of the article).
Instead you could try how to make your own threaded library responsive by 
saying how this can be achieved and how that library should then be used.

In addition I would encourage you to rewrite your first example to use the 
ParameterizedThreadStart Delegate 
(http://msdn2.microsoft.com/en-us/library/system.threading.parameterizedthreadstart.aspx),
 
since this is the standard way for invoking threads with parameters in the 
2.0 version of .NET.

The callback example looks quite good. But If you like you could show how to 
use delegates to execute methods synchronously with DynamicInvoke or "normal" 
invocation wit paranthesis and asynchronously by using the BeginInvoke and 
EndInvoke methods as well as wheres the difference between them (which method 
is being excecuted on what thread, which thread has to wait till the delegate 
executes,...)

But, keep up the good work and please mind the coding guidelines for mono  
(http://mono-project.com/Coding_Guidelines) when submitting code samples.

Kind Regards,
Valentin S.

On Thursday 15 March 2007 13:07, you wrote:
> I get no password or even write access :)
> So, i attach a text file with the info to add to this article.
>
> Bye
> Luciano
>
> >From: Miguel de Icaza <[EMAIL PROTECTED]>
> >To: Luciano _ <[EMAIL PROTECTED]>
> >CC: [EMAIL PROTECTED], mono-docs-list@lists.ximian.com
> >Subject: Re: [Mono-docs-list] Adding a link to
> >StudentProjectsinContributingand ThreadsBeginnersGuide
> >Date: Tue, 13 Mar 2007 12:45:30 -0400
> >MIME-Version: 1.0
> >Received: from erandi.dom ([130.57.22.201]) by
> >bay0-mc5-f11.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Tue,
> >13 Mar 2007 09:46:55 -0700
> >Received: by erandi.dom (Postfix, from userid 500)id A086ACDB11; Tue, 13
> >Mar 2007 12:45:30 -0400 (EDT)
> >X-Message-Info:
> >LsUYwwHHNt3660MmjhEvYg2f34OAemlK+ZzoV09lDsZmbz8QigGIQtU5Yvr3lK0P
> >References: <[EMAIL PROTECTED]>
> >Organization: Novell, Inc. X-Mailer: Evolution 2.6.0 Return-Path:
> >[EMAIL PROTECTED]
> >X-OriginalArrivalTime: 13 Mar 2007 16:46:55.0972 (UTC)
> >FILETIME=[35BDFA40:01C7658F]
> >
> >Hey,
> >
> > > It is an excelent article. I was looking for this info in the past, and
> > > someone help me with this at #Irc. Could i improved a little bit? Like
> > > adding info about passing info to thread method? How do i do this? I
> >
> >haven't
> >
> > > got write access.
> >
> >Send me your full name and I can set up an account for you
>
> _
> Visita MSN Latino Noticias: Todo lo que pasa en el mundo y en tu paín, ¡en
> tu idioma! http://latino.msn.com/noticias/
___
Mono-docs-list maillist  -  Mono-docs-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-docs-list


Re: [Mono-docs-list] Adding a link to StudentProjectsinContributingand ThreadsBeginnersGuide

2007-03-15 Thread Luciano _

I get no password or even write access :)
So, i attach a text file with the info to add to this article.

Bye
Luciano




From: Miguel de Icaza <[EMAIL PROTECTED]>
To: Luciano _ <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED], mono-docs-list@lists.ximian.com
Subject: Re: [Mono-docs-list] Adding a link to 
StudentProjectsinContributingand ThreadsBeginnersGuide

Date: Tue, 13 Mar 2007 12:45:30 -0400
MIME-Version: 1.0
Received: from erandi.dom ([130.57.22.201]) by 
bay0-mc5-f11.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Tue, 
13 Mar 2007 09:46:55 -0700
Received: by erandi.dom (Postfix, from userid 500)id A086ACDB11; Tue, 13 
Mar 2007 12:45:30 -0400 (EDT)
X-Message-Info: 
LsUYwwHHNt3660MmjhEvYg2f34OAemlK+ZzoV09lDsZmbz8QigGIQtU5Yvr3lK0P

References: <[EMAIL PROTECTED]>
Organization: Novell, Inc. X-Mailer: Evolution 2.6.0 Return-Path: 
[EMAIL PROTECTED]
X-OriginalArrivalTime: 13 Mar 2007 16:46:55.0972 (UTC) 
FILETIME=[35BDFA40:01C7658F]


Hey,

> It is an excelent article. I was looking for this info in the past, and
> someone help me with this at #Irc. Could i improved a little bit? Like
> adding info about passing info to thread method? How do i do this? I 
haven't

> got write access.

Send me your full name and I can set up an account for you



_
Visita MSN Latino Noticias: Todo lo que pasa en el mundo y en tu paín, ¡en 
tu idioma! http://latino.msn.com/noticias/

Passing parameters to threads
The ThreadStart delegate doesn't take any parameters, so, the parameters 
must be stored in somewhere else.
A good way to do this, is to create a new object which contains the async 
method, and store the parameters in some of

it properties.
An example of this is:

using System;
using System.Threading;

namespace ThreadGuideSamples
{
class ThreadCaller
{
static void Main()
{
ThreadCaller myCaller = new ThreadCaller();
}

public ThreadCaller()
{
SecondThreadObject myThreadObject = new SecondThreadObject("Test 
Param"); // Constructor get the parameter
myThreadObject.Parameter2 = 10; // Another value, not assigned at 
constructor
Thread myThread = new Thread(new 
ThreadStart(myThreadObject.MyAsyncMethod));

myThread.Start();
}
}

class SecondThreadObject
{
protected string Param1;
protected int Param2;

public SecondThreadObject(string parameter1)
{
this.Param1 = parameter1;
}

public int Parameter2
{
set
{
this.Param2 = value;
}
}

public void MyAsyncMethod()
{
Console.WriteLine("The value passed in the Constructor is '{0}'", 
this.Param1);
Console.WriteLine("The value passed in the Property is '{0}'", 
this.Param2);

for(int x = 0; x < 50; x++)
Console.WriteLine(x);
Console.ReadKey();
}
}
}

Accessing to main thread with callback
In some applications you need to access to the caller thread (the main 
thread) [0]. In this case you can use

a callback delegate to access to it, like this:

using System;
using System.Threading;

namespace ThreadGuideSamples
{
public delegate void MyCallBack(int Response);

class ThreadCaller
{
static void Main()
{
ThreadCaller myCaller = new ThreadCaller();
}

public ThreadCaller()
{
SecondThreadObject myThreadObject = new 
SecondThreadObject(this.OnResponse); // Constructor get the callback 
parameter
Thread myThread = new Thread(new 
ThreadStart(myThreadObject.MyAsyncMethod));

myThread.Start();
}

protected void OnResponse(int response)
{
Console.WriteLine("Value returned to main thread 
{0}", response);
/*
If you on Gtk# you can use like:
Gtk.Application.Invoke ( delegate {
// My Changes to the gui
});

 */

}
}