J
Jerry Houston
In a winform application, I use worker threads to perform asynchronous tasks
(e.g., mail merge with Word). The thread procs need to gather some user
options from controls in the UI, and I know that must be done using a
delegate that's running on the main UI thread. (Can't safely access a
window from a thread different than the one that created the window.)
Rather than write and execute 7 separate methods to get things like checkbox
and radio button values, I wrote two methods, one of which accepts 3 'out'
parameters and the other accepts 4 'out' parameters. Thus, I can pass the
parameters via the delegate invocation, and upon return from it, they should
contain my values from the UI. Trouble is, they don't.
My first indication that something was wrong was when the compiler insisted
that my parameter variables be initialized before invoking the delegate.
Since both the delegate and the method itself adorn those parameters with
the 'out' keyword, the compiler should not have required that. In fact,
that's the only real difference between an 'out' parameter and a 'ref'
parameter.
My second clue was when, upon return from the invocation, the initial values
were still in those variables, despite my having seen them reassigned when I
traced through the method call. It appears that marshalling is being done
only in the IN direction, but not the OUT direction.
Has anyone else here come up against this issue? If so, what did you end up
doing? Thanks!
(e.g., mail merge with Word). The thread procs need to gather some user
options from controls in the UI, and I know that must be done using a
delegate that's running on the main UI thread. (Can't safely access a
window from a thread different than the one that created the window.)
Rather than write and execute 7 separate methods to get things like checkbox
and radio button values, I wrote two methods, one of which accepts 3 'out'
parameters and the other accepts 4 'out' parameters. Thus, I can pass the
parameters via the delegate invocation, and upon return from it, they should
contain my values from the UI. Trouble is, they don't.
My first indication that something was wrong was when the compiler insisted
that my parameter variables be initialized before invoking the delegate.
Since both the delegate and the method itself adorn those parameters with
the 'out' keyword, the compiler should not have required that. In fact,
that's the only real difference between an 'out' parameter and a 'ref'
parameter.
My second clue was when, upon return from the invocation, the initial values
were still in those variables, despite my having seen them reassigned when I
traced through the method call. It appears that marshalling is being done
only in the IN direction, but not the OUT direction.
Has anyone else here come up against this issue? If so, what did you end up
doing? Thanks!