Notifications
Clear all

[Closed] Dotnet: Updating a UI control from a different thread

 lo1

Hi

What I’m trying to do is update the progress of an ftp transfer in the UI (represented by a datagridview row and executed by a webClient object).

The problem is the transfer is called asynchronously and the handler for the ‘progresschanged’ can not touch the UI thread.

How do I create the delegate that is necessary to update the UI in maxscript? :shrug:

25 Replies

i believe you’re looking for:

<Control>.BeginInvoke()

MSDN has an example:
http://msdn.microsoft.com/en-us/library/0b1bf3y3.aspx

EDIT: or maybe <Control>.Invoke()
MSDN example: http://msdn.microsoft.com/en-us/library/a1hetckb.aspx

 lo1

Thanks for your reply.

I understand I need to invoke it using a delegate, but the question is how do I create a delegate to a maxscript function?

To update UI from different thread this is what you need to do:


  delegate void UpdateSomeUiElement(string updatetext)
  
  void UpdateIT(string text)
  {
  	 if (!InvokeRequired)
  	 {
  		   //Code to update UI without invoke
  	 }
  	 else
  	 {
  		   Invoke(new UpdateSomeUiElement(UpdateIT), new object[] { text });
  	  }
  }
  
 lo1

Thanks. I know this method, but my problem is that the code I need to run is maxscript code, not c# code.
My question was can I create a delegate in maxscript (with dotnet system.delegate.createdelegate method) that would reference a maxscript function?

To run maxscript code you could use:

MaxscriptSDK.ExecuteMaxscriptCommand();

If this is applicable to your problem.

 lo1

Hi
I don’t think it’s applicable to my problem, but I’d love to know what is MaxscriptSDK ? Which platform are we talking about?

If you install 3ds max 2010 SDK you will get .NET assemblies with it (i dont know does 2009 has it).

Then you can import ManagedServices.dll in to your C# lib and use

ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand(string);

string can be any maxscript command so you can basically execute maxscript from C# class.

Allso you can get output using ManagedServices.dll from maxscript wethers its bool, int, string, color etc…
You will find all you need in SDKs help files.

you can view my WIP preview this app has only 10 lines of maxscript the rest is in the dll.

 lo1

nice to know, thanks.

No problem, I’m glad i could help.

Page 1 / 2