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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:38:44+00:00 2026-05-25T19:38:44+00:00

In my application I host a WCF service: private void StartService() { m_serviceHost =

  • 0

In my application I host a WCF service:

private void StartService()
{
    m_serviceHost = new ServiceHost(typeof(...));
    m_serviceHost.Open();
}

private void button1_Click(object sender, EventArgs e)
{                        
    Thread t = new Thread(StartService);
    t.IsBackground = true;
    t.Start();
    // ...
}

The service itself has just one method:

public void SendMessage(string message)
{
    MessageBox.Show(String.Format("Message '{0}' received on thread {1} : MessageLoop = 
        {2}", message, Thread.CurrentThread.GetHashCode(), Application.MessageLoop), 
        "MessagingService.SendMessage()");
}

When the client calls this operation I get the following responses:

Message 'hello client : message 9 recieved on thread **12**
Message 'hello client : message 9 recieved on thread **15**
Message 'hello client : message 9 recieved on thread **17**
...

Why does the thread id always change? When I created the ServiceHost I only put him on another thread! im not re-putting him on another thread each time… only once

How can i put the host in another thread (like i did) and to get only single background thread id ?

  • 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-25T19:38:45+00:00Added an answer on May 25, 2026 at 7:38 pm

    IIRC correctly the ConcurrencyMode.Single does not guarantee that a single thread is used…it guarantees that only a single thread can access the service instance…thus preventing concurrency issues that might arrise if two (or more) threads use the same service instance (state might get corrupted for instance).

    I guess you want to enforce one thread to handle all the calls so everything gets done sequentially and no state gets corrupted. But with the default InstanceContextMode (PerCall) each call gets its own service instance anyway. And with the ConcurrencyMode set to single you are sure that only one thread accesses a service instance.

    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, 
        InstanceContextMode = InstanceContextMode.PerCall)]
    public class MessageService : IMessageService
    {
        public string ReturnMessage()
        {
            return String.Format("Thread {0}", Thread.CurrentThread.ManagedThreadId);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following WCF service host console application: static void Main(string[] args) {
Is there a way to host wcf service application with Plesk Panel 9.2 in
I know with .NET we can host wcf service from a console application without
I host a wcf workflow service within my ASP.NET MVC2 application. I need to
I would like to start a new instance of a wcf service host from
I am totally new to this and trying to host the simplest WCF service
I have a service application that host several WCF endpoints through different bindings. I
Hey, I host my asp.net application with wcf service on IIS 7 and I
I need to host a WCF service inside a Windows Forms application and call
Service - WCF Service Host - Windows Service Client - ASP.Net Web application I

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.