Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For ICommand & DelegateCommand Which Thread Does it Run On?

My application uses ICommands to bind methods to Buttons.

I initialized these commands as follows :

AnswerCommand = new DelegateCommand(AnsCommandExecute, AnsCommandCanExecute);

I want to know ifAnsCommandExecute() method will work on UI thread or Background thread?

If it works on UI thread do I have to create another thread for this execute() method as my application performs lot of processing in background.

Also my application uses TCP to communicate with one another application. so, for better performance Do I have to use different threads for Receiving Data, Processing, and Sending Data. what will be the best Threading approach for such applications?

like image 438
deathrace Avatar asked Oct 06 '22 10:10

deathrace


1 Answers

Simplest way to find whether AnsCommandExecute() method works on main thread or not is to put break point in the method and check call stack.

Quick answer is yes - AnsCommandExecute() will execute on main thread.

To answer your threading requirement, you can invoke content inside AnsCommandExecute() on separate thread. This will make UI responsive.

If you are going to receive responses asynchronously, you then have to move operation back to main thread with help of "Dispatcher". More also at the Dispatcher documentation.

like image 121
RockWorld Avatar answered Oct 10 '22 02:10

RockWorld