Problem:
I am having a problem with a thread which is altering a long (Int64) variable. This variable is also accessed from outside the thread.
It gives me the following error message:
"cross-thread operation is not valid"
Solution 1: volatile keyword
I tried to solve this by marking my variable as volatile. But It gave me the following interesting error: A volatile field can not be of the type long
I think this is rather interesting. It seems like the Int16 (short) and Int32 (int) support it, but the Int64 (long) does not. Pretty lame if you ask me. And as far as I found on google it seems java does support the volatile keyword for variables of the type long. Pretty silly in my oppinion.
Solution 2: locking
I tried using a lock instead. But it did not work neither. It gave me the following error: "'long' is not a reference type as required by the lock statement." Yup, the lock statement only protects reference-type variables.
Solution 3: google, The Code Project, ...
When you use google you get all kind of fancy stuff throwing at your head that seems to have nothing to do with it.
Most results talk about how to do operations on Control's which was created by other threads. => Not my problem.
Suggestions?
I guess I could just use an int (Int32) instead of my long. But actually the variable should hold a filesize. So, that would restrict my filesize to about 2 GB.
As always there is probably a way around it that I do not know yet. It would be nice if somebody could point it out to me. Thank you in advance


. Thank you in advance
Reply With Quote