I'm still learning how to make my own async methods, I've been using the common async ef methods, but this time I have to use a third party dll, but the main method isn't async. This how it simple works.
thirdpartymethod tMethod = new thirdpartymethod();
tMethod.data1 = "test";
tMethod.data2 = 5;
string tResult = tMethod.GenerateSignature();
That method, consumes a webservice and generate a transaction file on drive C.
I tried something like this:
string tResult = await Task.Run(() => tMethod.GenerateSignature());
And It kind of works, because the screen doesn't lock, but I get an error that the file is in use (That's the transaction file that the thirdparty method creates).
I've been searching, but most people want run async method sync.
Thank you for your response.
Edit:
It only happens when I tried to call it async, I used this third party dll for about a month with no problem, but it locks the screen if the user have a bad internet connection.
I know what a file in use is, but it just happend when I did the change, I can't change the thirdparty file.
My question got flaged by an Admin, so I'll keep looking somewhere else. Thank you to everybody that took the time to answer.
Edit:
The error is:
The process cannot access the file 'C:\SIGNATURES\signature_response.json' because it is being used by another process.
I found that they have a boolean option to avoid the use of the transaction file, so I turned it off and now it works. Another thing I noticed is that they use an absolute path so if there is not drive C or no Admin privileges will throw an error. (I checked that with an IL decompiler). So I'm not going to use that automatic transaction file, Ill do it my way becuase the information on the transacion file is part of the result string that I receive.
Thank you all.