Results 1 to 2 of 2

Thread: [RESOLVED] making a Int64-variable threadsafe

  1. #1
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 02
    Location
    Belgium
    Posts
    502

    Resolved [RESOLVED] making a Int64-variable threadsafe

    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
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

  2. #2
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 02
    Location
    Belgium
    Posts
    502

    Re: making a Int64-variable threadsafe

    sorry, I made a wrong conclusion.

    the cross-thread operation error I am receiving is not about the Int64. It is a crossthread operation on a control.

    I will close this topic and will pose the real question in a new topic.
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •