The program I am working on has a long task to run, at the end of the task it puts some text in the clipboard.
When I run the task straight off, "runTask()" it can grab the text off the clipboard without any problems.
here is the code I am using to grab the text from the clipboard:
However, its a fairly long task (10-15 seconds, maybe longer) and I dont want the form to become unresponsive. So I decided to use a backgroundworker to launch the task:
However, at the end of the task, when it is supposed to have copied text from the clipboard, I just get an empty string "".
When I use runTask() by itself, grabs text fine from clipboard, when I use runTask from inside the background worker, grab an empty string.
If I manually press ctrl-v in something like notepad, the text is correctly in the clipboard, its just not being retrieved.
Any help would be much appreciated, thanks in advance.
*edit*
This is kinda important, forgot to say this, I am still in the Asynchronous thread when I am trying to get the text from the clipboard, so its not like the Asynchronous thread finished after I tried to grab the text from the clipboard as would happen if they were in different threads.
When I run the task straight off, "runTask()" it can grab the text off the clipboard without any problems.
here is the code I am using to grab the text from the clipboard:
VB.NET:
private sub runTask()
...
Dim strTaskResult As String = My.Computer.Clipboard.GetText()
...
end sub
However, its a fairly long task (10-15 seconds, maybe longer) and I dont want the form to become unresponsive. So I decided to use a backgroundworker to launch the task:
VB.NET:
bgwTaskRunner.RunWorkerAsync()
Private Sub bgwTaskRunner_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwTaskRunner.DoWork
runTask()
End Sub
However, at the end of the task, when it is supposed to have copied text from the clipboard, I just get an empty string "".
When I use runTask() by itself, grabs text fine from clipboard, when I use runTask from inside the background worker, grab an empty string.
If I manually press ctrl-v in something like notepad, the text is correctly in the clipboard, its just not being retrieved.
Any help would be much appreciated, thanks in advance.
*edit*
This is kinda important, forgot to say this, I am still in the Asynchronous thread when I am trying to get the text from the clipboard, so its not like the Asynchronous thread finished after I tried to grab the text from the clipboard as would happen if they were in different threads.