"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"Cor Ligthert" <no************@planet.nl> wrote in message
news:u$**************@TK2MSFTNGP09.phx.gbl... Mythran,
I don't like to set things global either
What I do, is this
Class my
public event ready
Private mydataset
Public sub new(byval ds as dataset)
mydataset = ds
end sub
Public sub myproc
at the end raiseevent ready
end sub
dim mymy as new my(mydataset) 'the dataset is in the main thread
AddHandler my.Ready, AddressOf myReadyEvent
ThreadMy = New System.Threading.Thread(AddressOf mymy.myproc)
ThreadMy.Name = "My"
ThreadMy.Start.Start()
I have to go, I hope this is clear,
Think as well twice why you want to use threading here. Threading cost in
your process surely extra processing time, and you will loose that as
well in througput time because of the fact that you have no seperated not
dependable processes running at the same time. They are all sequential.
I hope this helps,
Cor
[Yes, I am in vb.net group but I started writing this in C# so that is what
I'm posting the code in...sorry]
I tried the above (in C# anyways) and it gives me the following error
message when I bind the DataTable (not DataSet) to a DataGrid (for testing):
"Controls created on one thread cannot be parented to a control on a
different thread."
The way I have it set up is...(off top of head, won't compile...most likely)
form code -
execute method:
DataTable dt = (new DataSet()).Tables.Add("tblSample");
dt.Columns.Add("LastName");
dt.Columns.Add("FirstName");
engine = new ReportEngine(dt);
engine.DataReady += new DataReadyEvent(Engine_DataReady);
ThreadStart threadStart = new ThreadStart(engine.RaiseEvent);
Thread childThread = new Thread(threadStart);
childThread.Name = "Child Thread";
childThread.Start();
Engine_DataReady(DataTable Data):
try {
grdResults.DataSource = Data;
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
end of form
Namespace code:
public delegate void DataReadyEvent(DataTable Data);
ReportEngine code:
public event DataReadyEvent DataReady;
private DataTable mData;
ReportEngine(DataTable Data) constructor:
mData = Data;
RaiseEvent method:
mData.Rows.Add(new string[] { "Potter", "Kip" });
if (DataReady != null) {
DataReady(mData);
}
end of ReportEngine code.
The exception is raised in the Engine_DataReady event handler where I'm
binding the DataTable to the DataGrid's DataSource property. I have
narrowed it down in the past and believe it's still the same, the DataRow
that was created on the child thread is the problem here. When I step
through to the Engine_DataReady handler, I can do Data.Rows[0]["LastName"]
and it gives me "Potter". If I remove the row from the DataTable and then
continue the program, it binds correctly (but no data, of course).
Hope this is still clear enough. Let me know what you think I should do in
this case please :)
Thanks in advance, again, you are a big help in this.
Mythran