Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 351255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:37:36+00:00 2026-05-12T11:37:36+00:00

Now with all the WaitOne and ManualResetEvent stuff working (thanks!) I’ve got one last

  • 0

Now with all the WaitOne and ManualResetEvent stuff working (thanks!) I’ve got one last problem, that is running a function in Class A from a thread which is part of Class B – again allow me to illustrate …

Look at the function “DoIt(obejct param)” within class A, this needs to be called by class A (as shown) as well as by the thread in class B (as shown) … how can this be accomplished? Would some form of delegates help?

class A
{
private ManualResetEvent manualResetEvent;
int counter = 0;

public A()
    {
    manualResetEvent = new ManualResetEvent(false);
    B child = new B(manualResetEvent);

    if (manualResetEvent.WaitOne(1000, false))
        {
        ... do the work I was waiting on ...
        }

    ... do more work ...
    // Call the function DoIt from within A //
    DoIt(param)

    }

    // This is the function that needs to be called from A and thread in B
    void DoIt(object param)
    {
    counter++;
    ... do something with param with is local to A ...
    }

};


Class B
{
private ManualResetEvent manualResetEvent;

public B(ManualResetEvent mre)
    {
    manualResetEvent = mre;
    Thread childThread = new Thread(new ThreadStart(Manage));
    childThread.IsBackground = true;
    childThread.Name = "NamedPipe Manager";
    childThread.Start();

    private void Manage()
        {
        ... do some work ...
        ... call some functions ...

        // Calling the function from Class A, obviouslly doesn't work as-is
        DoIt(param);

        manualResetEvent.Set();

        ... do more work ...
        ... call more functions ...
        }
    }
};

Any one have any suggestions on how I can accomplish this task in a thread-safe manner?
Any help would be much appreciated.
Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:37:36+00:00Added an answer on May 12, 2026 at 11:37 am

    Given your current design the simplest thing would be to pass in A to your object B, just like your doing with the manualresetevent:

    B child = new B(this, manualResetEvent);
    ... etc...
    
    Class B
    {
    private A parent;
    private ManualResetEvent manualResetEvent;
    
    public B(A p, ManualResetEvent mre)
    {
        parent = p;
        manualResetEvent = mre;
        ... etc ...
    
    
    private void Manage()
    {
        ... do some work ...
        ... call some functions ...
    
        parent.DoIt(param);
    
        ... etc...
    

    Of course you need to mark A.DoIt as public.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We recently moved our github from one account owner to another, and now all
I have one mainViewController and I have a UIPickerView. Now all is set up
As of rite now all I have is one spinner with three options, what
Jekyll was working fine for me few weeks back but now all of a
Ok I have a reportviewer that has worked perfectly up untill now, now all
I am working on a simple client/server program and for now all it is
My hoster has recently upgraded PHP to 5.3.8 and now all my installations that
I have a simple method that creates numbers 13:35 - 14:31. Right now all
I have this code : $('.hotel_photo_select').fadeOut(500, function () { alert(Now all '.hotel_photo_select are hidden');
I have multiple classes that all derive from a base class, now some of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.