Variable scoping
Considering this code:
Trying to compile, within the "ShowOrders" function, the
client.AddCallback<TestObject>(ShowOrders);
line gives the error :
Use of unassigned local variable 'test'
Why does it not complain about testString
?16 Replies
$scopes
thing a
is available in scope A
and scope B
thing b
is available only in scope B
Also, you have to understand top-level code, and that what it actually does, is puts your code into a class and a method
So your
really becomes something akin to
Or, well, wait
In your case it's actually a local function
yeah you shot yourself in the foot by going the top-level statement approach
I'm just trying out some lib with a simple program 🙂
yeah i think the middle function becomes a local one but i wouldnt be sure i avoid tls
You can use TLS, you just need to understand what it does
Generally speaking, move your functions to the end of the file
The client is the lib, therefor the test.Test would be accessed via there?
After the top-level code
Ok, so considering this
Also, I wonder about that
.AddCallback()
, smells of a callback-hell-ish thing from pre-async
times
I'd need to know what the lib is to tell for sure, thoIts something I wrote a while ago, with the callback added to an object to
invoke
them later onWell, in any case, you're passing a local function as a delegate
So chances are it's non-capturing
Alright, I think that's it. thx 🙂
You should not be using BackgroundWorker
Task.Run vs BackgroundWorker: Intro
This is an introductory post for a new series that I’ll be doing comparing BackgroundWorker to Task.Run (in an async style). I always recommend Task.Run, and I have already written a long post describing why, but I still see some developers resisting the New Way of Doing Things (TM). So this will be a short series where I’ll compare the code sid...