Page 1 of 1

Multiple Threads

Posted: 18 Jan 2012, 12:33
by dragon_chichi
Hello
How i can make a separate Thread from inside Ventuz (i.e. in my Ventuz Script node). I need read data from Excel (many difference data so workbook node isn't suited). If does it without separate Thread the Scene is hanging. Here is my code:

public bool OnUpdate(int arg)
{
Thread ExcelThread = new Thread(new ThreadStart(this.MyThread));
ExcelThread.Start();
return false;
}

public void MyThread()
{
try
{
app = new Excel.Application();
Update_Info = "OK";
s = "AlbumInit";
AlbumInit();
s = "ReadConfig";
ReadConfig();
s = "LoadItems";
LoadItems();
s = "Output_Current_Upgrade";
Output_Current_Upgrade();
test_size = "photo: " + Photo.AlbumQnt.ToString() + "video: " + Video.AlbumQnt.ToString() + "mesh: " + Mesh.AlbumQnt.ToString() + "audio: " + Audio.AlbumQnt.ToString();
changed = true;
s = "finish";
}
catch
{
Update_Info = "There are some errors";
}
finally
{
app.Quit();
app = null;
book = null;
sheets = null;
sheet = null;
cell = null;
}
}

Methods MyThread( ) and OnUpdate( ) ReadConfig( ) etc are members of Script class. Functions like ReadConfig( ), LoadItems( ) are my function which is worked well. In the issue Ventuz has crashed with: (System.NullReferenceException) in "Ventuz.exe [8296]".

Re: Multiple Threads

Posted: 18 Jan 2012, 19:34
by Ralf Stanke
Hi, I can't realy say what is wrong in your script - so I'm just guessing:
  • Ensure that you do not update any script properties from that extra thread. Store the actual results in member varibales and mark them as NEW. The GenerateValues method should see the updated data and transfer it to the output properties in the main thread. (don't forget to return true, to let Ventuz know about the new values)
  • Try to enabled the Debugging mode to figure out what goes wrong. See user manual (you'll need a Visual Studio installed)
    http://www.ventuz.com/support/help/late ... alDebugger
Best regards and good luck
Ralf

Re: Multiple Threads

Posted: 19 Jan 2012, 07:48
by joschy
Hi,
for exel stuff I use a this:

http://www.gemboxsoftware.com/spreadsheet/free-version

The free version of a C# library, very useful. May be it help.

greatings

Re: Multiple Threads

Posted: 19 Jan 2012, 07:53
by joschy
For exel stuff I use this:

http://www.gemboxsoftware.com/spreadsheet/free-version

Nice free C# library

joschy

Re: Multiple Threads

Posted: 23 Jan 2012, 07:54
by dragon_chichi
Big thanks!!!
The problem was I updated Script properties:) I deleted line "changed = true;" from end of TRY block in MyThread() and it got worked. But now i dont undestand why?? Inside my Output_Current_Upgrade() function i have line "changed = true;". Does Ventuz ignore it???

Sorry maybe it is foolish questions but: (1) How "mark them as NEW"???
(2)How call the "GenerateValues method"?