i am currently trying to use the method bellow in my async Task but im getting the error when im trying to use the StartSTATask:
The type arguments for method 'PrintService.StartSTATask(Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
This is the StartSTATask method
private Task<T> StartSTATask<T>(Func<T> func)
{
var tcs = new TaskCompletionSource<T>();
Thread thread = new Thread(() =>
{
try
{
tcs.SetResult(func());
}
catch (Exception e1)
{
tcs.SetException(e1);
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
return tcs.Task;
}
this is where i try to use StartSTATask:
public async Task printLabelEindcontroleAsync(LabelEindControleDto label)
{
await StartSTATask(() => {
var config = new MapperConfiguration(cfg => cfg.CreateMap<LabelEindControleDto, LabelEindcontrole>());
var mapper = new Mapper(config);
LabelEindcontrole labelEindcontrole = mapper.Map<LabelEindcontrole>(label);
new SuplaconPrint.Queries.LabelEindcontrole(labelEindcontrole);
});
}
await StartSTATask(async () => {...});? In order toawaitwe have to returnTask- Dmitry Bychenko