The .NET framework is 4.0.
If you run the following methods in the console application, Process.Start in Convert will stop processing (no exceptions will occur, but will not continue):
In addition, Process.Start has successfully invoked external applications, and the task manager has confirmed that the process is complete.
Invoking this method from the WindowsForm application will exit successfully.
public CancellationTokenSourceConvertAsync<T>(object obj,string[] files, Listener listener){
var cancellation=new CancellationTokenSource();
var task = new Task(
( ) = > {
try{
Task convertedTask = null;
Action<object>action=new Action<object>(obj)=>{
try{
listener.oneFile(obj);
return;
} catch(Exception ex2){
Debug.WriteLine(ex2);
return;
}});
foreach(var file in files){
if(cancellation.IsCancellationRequested) return;
Debug.WriteLine("before:"+file);
var converted=Convert(obj,file); /*<- where Process.Start() call*/
Debug.WriteLine("after:"+converted);
if(converted==null)break;
if(convertedTask==null){
convertedTask = newTask(action,ab,cancellation.Token);
convertedTask.Start();
} else {
convertedTask=convertedTask.ContinueWith(arg)=>action(converted), cancellation.Token);
}
}
if(convertedTask!=null)convertedTask.Wait();
listener.allDone();
}catch(Exceptionex){
Debug.WriteLine(ex);
return;
}
},cancellation.Token);
task.Start();
return cancellation;
}
I would appreciate it if you could let me know the above.Thank you for your cooperation.
c# asynchronous
The information was not disclosed, but the console application was waiting in Console.ReadLine() after calling ConvertAsync.
However, I changed the return value to Task as shown below, and after waiting at Task.Wait() on the console application side, it ended normally.The cause is still unknown.
public Task ConvertAsync<T>(object obj, string[] files, listener listener){
var cancellation=new CancellationTokenSource();
var task = new Task(
( ) = > {
try{
Task convertedTask = null;
Action<object>action=new Action<object>(obj)=>{
try{
listener.oneFile(obj);
return;
} catch(Exception ex2){
Debug.WriteLine(ex2);
return;
}});
foreach(var file in files){
if(cancellation.IsCancellationRequested) return;
Debug.WriteLine("before:"+file);
var converted=Convert(obj,file); /*<- where Process.Start() call*/
Debug.WriteLine("after:"+converted);
if(converted==null)break;
if(convertedTask==null){
convertedTask = newTask(action, converted, cancellation.Token);
convertedTask.Start();
} else {
convertedTask=convertedTask.ContinueWith(arg)=>action(converted), cancellation.Token);
}
}
if(convertedTask!=null)convertedTask.Wait();
listener.allDone();
}catch(Exceptionex){
Debug.WriteLine(ex);
return;
}
},cancellation.Token);
task.Start();
return task;
}
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.