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 8983199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:46:54+00:00 2026-06-15T20:46:54+00:00

I have codes written in native C++ that controls other processes (client processes) created

  • 0

I have codes written in native C++ that controls other processes (“client processes”) created by CreatePrcess() and other Windows APIs
Then client processes (console, single-thread) wait for the message MSG_OK from the “server” process and resume running when the message is received.
I used PostThreadMessage() and it worked fine.

int MSG_OK = RegisterWindowMessage("MSG_OK");
void run(TCHAR* path) {
    STARTUPINFO si={0,}; si.cb=sizeof(STARTUPINFO); si.dwFlags=0;
    PROCESS_INFORMATION pi;
    CreateProcess(NULL, path, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
    Sleep(1000); // Just for simplicity. Actual code is message-based
    PostThreadMessage(pi.dwThreadId, MSG_OK, 0, 0);
    CloseHandle(pi.hProcess);   // closing process handle makes usage count 1
    CloseHandle(pi.hThread);    
}

Now I’d like to rewrite the code in C#, using p/invoke’s as little as possible.
The following is the code I’m working on:

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool PostThreadMessage(uint threadId, int msg, IntPtr wParam, IntPtr lParam);

public void run(string path) {
    Process proc = new Process();
    ProcessStartInfo si = new ProcessStartInfo();
    si.FileName = path;
    proc.StartInfo = si;
    proc.Start();
    uint threadId; // <----?
    PostThreadMessage(threadId, MSG_OK, 0, 0);
    proc.Dispose();
}

I found C# classes such as Process and ProcessStartinfo but couldn’t find any member similar to dwThreadId. Is there any?

EDIT: Since the client process is a single thread app,

 proc.Threads[0].id

seems to be the threadId I’m looking for. Am I doing something wrong?

  • 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-06-15T20:46:56+00:00Added an answer on June 15, 2026 at 8:46 pm

    Please see this thread.

    I would consider using some other approaches like mutexes, events or semaphores.

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

Sidebar

Related Questions

I have written code in native ANSI C++ that does some complicated numerical analysis.
I have an SDK that is written primarily in C#. We have some native
I have a Vendor.DLL (Native DLL, written in C++) that exposes many methods. Typically
I am using php and i have written codes to allow a user upload
I have written code that opens 16 figures at once. Currently, they all open
We have a client/server system where all communications are done using a native protocol
In my other question I found out that there is no whitelist for windows
Background: I have an application written in native C++ which uses the wxWidgets toolkit's
Environment I'm working on a C++ application that uses SQL Native Client 9.0 to
I have written this code (this is a snippet) that doesn't seem to be

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.