locked
Call a function on a class created by main process on a thread RRS feed

  • Question

  • Hi, I've a question that maybe its simple but here it goes: if i create a class[class 1] on the main process and acess that class[class1] from another class[class2] and thread (actually a task), the function from class1 executed on class2 will be async? I get confused with this things :P
    Sunday, October 18, 2015 6:27 PM

Answers

  • Hi Pau CP,

    A class is a template for creating objects.  A object is a storage space which is dynamically created. A thread is the smallest sequence of programmed instructions that can be managed independently by a scheduler. A object created by one thread can be used by another thread. A object doesn't belong to one thread.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Pau CP Monday, October 19, 2015 6:03 PM
    Monday, October 19, 2015 7:36 AM

All replies

  • Depends on what you mean by async, it's a very general term.

    If you're talking about C#'s notion of async method then it should be obvious that as long as the method isn't defined using the async keyword it is not async.

    If you're talking about the more general meaning of async then maybe it is since threads are involved. Given your vague and confusing description I can't tell for sure what you're doing. Main process probably means main thread, create class probably means instantiate class, the fact that a class is instantiated in a thread is usually irrelevant etc.

    You may get a more definitive answer if you post some sample code.

    Sunday, October 18, 2015 6:53 PM
  • Hi, I've a question that maybe its simple but here it goes: if i create a class[class 1] on the main process and acess that class[class1] from another class[class2] and thread (actually a task), the function from class1 executed on class2 will be async? I get confused with this things :P

    What's the purpose of this? And do you really know how to use Object Oriented Programming effectively? On one hand,  you were talking about keeping 50K user credentials in memory, and then you start asking this.

    Is this in regards to this same solution you are trying develop?

    Sunday, October 18, 2015 6:54 PM
  • What's the purpose of this? And do you really know how to use Object Oriented Programming effectively? On one hand,  you were talking about keeping 50K user credentials in memory, and then you start asking this.

    Is this in regards to this same solution you are trying develop?

    Yes, its the same solution, i've just solved it, i haven't tried to program anything for a long time and I make a mess in my head by myself. The thing was about handling login/logout functions simultaneously.
    Sunday, October 18, 2015 7:30 PM
  • Hi Pau CP,

    A class is a template for creating objects.  A object is a storage space which is dynamically created. A thread is the smallest sequence of programmed instructions that can be managed independently by a scheduler. A object created by one thread can be used by another thread. A object doesn't belong to one thread.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Pau CP Monday, October 19, 2015 6:03 PM
    Monday, October 19, 2015 7:36 AM
  • Hi Pau CP,

    A class is a template for creating objects.  A object is a storage space which is dynamically created. A thread is the smallest sequence of programmed instructions that can be managed independently by a scheduler. A object created by one thread can be used by another thread. A object doesn't belong to one thread.

    That being said, actually accessing an object from multiple threads will lead to Race Conditions unless it is carefully managed via lock statements/readonly access.

    The WinForms and WPF GUI classes had thread ownership mechanics actively added to them, because cross thread operation are very dangerous for them:
    Invoke

    Other classes might have a similar mechanic of "Thread ownership" too. In any case this must be manually added to the class and is not some default feature of the .NET Framework.

    Monday, October 19, 2015 6:44 PM