JaedenRuiner
Well-known member
- Joined
- Aug 13, 2007
- Messages
- 340
- Programming Experience
- 10+
Code:
Now, I believe, and though I could be wrong I doubt it, that there are lot crazy excessive thread protections going on that are unnecessary, basically trying to protect against cross-threaded assignments, but when it comes to reading data they are quite counterproductive. In lower-level languages (C, C++, Delphi) the threads don't protect themselves, it is up to the programmer to do it. THis I dont' mind, because when an Item is read only, the address is the address and the code doesn't care. But right now it does, because i'm using VB.net.
Now, I'm permitted the argument object passed into the WorkThread to process, which is boon to say the least, and I already found that global fields (stored in My.Application) are inaccessible from the workthread. Dunno why they are set to nothing, but they are. They are assigned once at start up and never assigned again, yet somehow in the thread they are nothing, so I have to store them in the constructor of MyObject() in order to use them in the worker thread.
However, the funny part is the InputEdit.Text line in the DoWork() event of the BackgroundWorker.
currently I'm testing some thing and this is my step by step process:
Why? It worked the first time I clicked button1, but the second time is when it complains about accessing the UI across multiple threads...
The data is static and from the time I click button1 to the time it reads inputedit.text in the workthread, it is impossible for the data in InputEdit.Text to change. i thought of using Invoke but that doesn't wait for the return of the invoked method. I need to access the UI for readonly purposes from across Thread lines. How do I do this?
Thanks
VB.NET:
inputEdit as Textbox
workThread as BackgroundWorker
Button1 as Button
sub button1_click()
_myobj = New MyObject(...params...)
workthread.runworkerasync(_myobj)
end sub
sub workthread_dowork(e as args)
obj as myobject = e.argument
try
if obj.OpenFile(inputedit.text) then
obj.execute
else
e.cancel = ture
catch ex as exception
msgbox(ex.message)
end try
e.result = obj
end sub
Now, I believe, and though I could be wrong I doubt it, that there are lot crazy excessive thread protections going on that are unnecessary, basically trying to protect against cross-threaded assignments, but when it comes to reading data they are quite counterproductive. In lower-level languages (C, C++, Delphi) the threads don't protect themselves, it is up to the programmer to do it. THis I dont' mind, because when an Item is read only, the address is the address and the code doesn't care. But right now it does, because i'm using VB.net.
Now, I'm permitted the argument object passed into the WorkThread to process, which is boon to say the least, and I already found that global fields (stored in My.Application) are inaccessible from the workthread. Dunno why they are set to nothing, but they are. They are assigned once at start up and never assigned again, yet somehow in the thread they are nothing, so I have to store them in the constructor of MyObject() in order to use them in the worker thread.
However, the funny part is the InputEdit.Text line in the DoWork() event of the BackgroundWorker.
currently I'm testing some thing and this is my step by step process:
- I run the application
- browse for the file
- click Button1
- The MyObject executes with an error - This is good because i knew it would. I'm testing that my db transaction is actually doing the commit/rollback. At least so far it is rolling back.
- Click Button1 again - basically attempting to alter the execution so it won't have an error this time and I can see if it commits.
Why? It worked the first time I clicked button1, but the second time is when it complains about accessing the UI across multiple threads...
The data is static and from the time I click button1 to the time it reads inputedit.text in the workthread, it is impossible for the data in InputEdit.Text to change. i thought of using Invoke but that doesn't wait for the return of the invoked method. I need to access the UI for readonly purposes from across Thread lines. How do I do this?
Thanks