Deadlock when constructing a Web Service!!!

Discussion in 'ASP .Net Web Services' started by Crnjan, Sep 11, 2006.

  1. Crnjan

    Crnjan Guest

    Hello!

    I recently found a strange phenomenon. I am using a simple Windows
    Application based application written in C# (lets name it
    TestWebServiceStrangePhenomenom). The TestWebServiceStrangePhenomenom
    application is started from another application which also redirects
    standard input from TestWebServiceStrangePhenomenom. The
    TestWebServiceStrangePhenomenom creates a new thread and within it,
    waits for input from app that started it (the redirected standard input
    stream is used for IPC). And now comes the strange part: if I add a new
    button to windows form and in the click action call some web service,
    the web service deadlocks!!!

    I wrote a simple demo application to demonstrate the problem.

    The TestWebServiceStrangePhenomenom code:

    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    new Thread( new ThreadStart( WaitForInput ) ).Start();

    // Give thread time to start...
    Thread.Sleep( 200 );
    }

    private void WaitForInput ()
    {
    Stream stdin = Console.OpenStandardInput();
    // Wait for input...
    int rv = stdin.ReadByte();
    }

    private void buttonHelloWorld_Click(object sender, EventArgs e)
    {
    // !!! Deadlock HERE !!!
    HelloWorld.Service hw = new
    TestWebService.HelloWorld.Service();
    string str = hw.HelloWorld();

    MessageBox.Show( str );
    }
    }


    For the web service I used the default ASP.Net Web Service sample
    (HelloWorld) that is automaticaly generated within VS2005.

    And also the code for starting the TestWebServiceStrangePhenomenom
    (another project):

    public partial class mainForm : Form
    {
    public mainForm()
    {
    InitializeComponent();
    }

    private void buttonBrowse_Click(object sender, EventArgs e)
    {
    if ( openFileDialog.ShowDialog() == DialogResult.OK )
    textBoxPath.Text = openFileDialog.FileName;
    }

    Process process = new Process();

    private void buttonRun_Click(object sender, EventArgs e)
    {
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardInput = true;
    process.StartInfo.FileName = textBoxPath.Text;
    process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    process.Start();
    }
    }

    If the TestWebServiceStrangePhenomenom has not got the input stream
    redirected, than the web service will work!
     
    Crnjan, Sep 11, 2006
    #1
    1. Advertising

  2. What do you mean by "deadlock". There's nothing in click handler that
    "deadlocks" in the normal mutli-threaded use of the work.

    Do you simply mean your application stops responding to user input while
    waiting for the web service operation to execute?

    --
    Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
    http://www.peterRitchie.com/blog/
    Microsoft MVP, Visual Developer - Visual C#


    "Crnjan" wrote:

    > Hello!
    >
    > I recently found a strange phenomenon. I am using a simple Windows
    > Application based application written in C# (lets name it
    > TestWebServiceStrangePhenomenom). The TestWebServiceStrangePhenomenom
    > application is started from another application which also redirects
    > standard input from TestWebServiceStrangePhenomenom. The
    > TestWebServiceStrangePhenomenom creates a new thread and within it,
    > waits for input from app that started it (the redirected standard input
    > stream is used for IPC). And now comes the strange part: if I add a new
    > button to windows form and in the click action call some web service,
    > the web service deadlocks!!!
    >
    > I wrote a simple demo application to demonstrate the problem.
    >
    > The TestWebServiceStrangePhenomenom code:
    >
    > public partial class Form1 : Form
    > {
    > public Form1()
    > {
    > InitializeComponent();
    > }
    >
    > private void Form1_Load(object sender, EventArgs e)
    > {
    > new Thread( new ThreadStart( WaitForInput ) ).Start();
    >
    > // Give thread time to start...
    > Thread.Sleep( 200 );
    > }
    >
    > private void WaitForInput ()
    > {
    > Stream stdin = Console.OpenStandardInput();
    > // Wait for input...
    > int rv = stdin.ReadByte();
    > }
    >
    > private void buttonHelloWorld_Click(object sender, EventArgs e)
    > {
    > // !!! Deadlock HERE !!!
    > HelloWorld.Service hw = new
    > TestWebService.HelloWorld.Service();
    > string str = hw.HelloWorld();
    >
    > MessageBox.Show( str );
    > }
    > }
    >
    >
    > For the web service I used the default ASP.Net Web Service sample
    > (HelloWorld) that is automaticaly generated within VS2005.
    >
    > And also the code for starting the TestWebServiceStrangePhenomenom
    > (another project):
    >
    > public partial class mainForm : Form
    > {
    > public mainForm()
    > {
    > InitializeComponent();
    > }
    >
    > private void buttonBrowse_Click(object sender, EventArgs e)
    > {
    > if ( openFileDialog.ShowDialog() == DialogResult.OK )
    > textBoxPath.Text = openFileDialog.FileName;
    > }
    >
    > Process process = new Process();
    >
    > private void buttonRun_Click(object sender, EventArgs e)
    > {
    > process.StartInfo.UseShellExecute = false;
    > process.StartInfo.RedirectStandardInput = true;
    > process.StartInfo.FileName = textBoxPath.Text;
    > process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    > process.Start();
    > }
    > }
    >
    > If the TestWebServiceStrangePhenomenom has not got the input stream
    > redirected, than the web service will work!
    >
    >
     
    Peter Ritchie [C# MVP], Sep 12, 2006
    #2
    1. Advertising

  3. Crnjan

    Crnjan Guest

    No. The executing stops within web service's constructor. The web
    service (Hello World) is running on local machine so their in NO way
    that web service could deadlock. The execution simply stops. If the
    same web service is invoked from other application the web service
    works without problems. The web service also works if it is invoked
    from same application if the standard input is not redirected as stated
    above.

    So to repeat the scenario:

    If the TestWebServiceStrangePhenomenom application is simply run (for
    example from VS2005 environment) than there is NO problem executing web
    service.

    If the TestWebServiceStrangePhenomenom application is run from other
    application that redirects TestWebServiceStrangePhenomenom's standard
    input, than web service doesn't work. Its execution stops when
    executing constructor:

    HelloWorld.Service hw = new TestWebService.HelloWorld.Service();


    Hope I was clear enough,
    crnjan


    Peter je napisal:
    > What do you mean by "deadlock". There's nothing in click handler that
    > "deadlocks" in the normal mutli-threaded use of the work.
    >
    > Do you simply mean your application stops responding to user input while
    > waiting for the web service operation to execute?
    >
    > --
    > Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
    > http://www.peterRitchie.com/blog/
    > Microsoft MVP, Visual Developer - Visual C#
    >
    >
    > "Crnjan" wrote:
    >
    > > Hello!
    > >
    > > I recently found a strange phenomenon. I am using a simple Windows
    > > Application based application written in C# (lets name it
    > > TestWebServiceStrangePhenomenom). The TestWebServiceStrangePhenomenom
    > > application is started from another application which also redirects
    > > standard input from TestWebServiceStrangePhenomenom. The
    > > TestWebServiceStrangePhenomenom creates a new thread and within it,
    > > waits for input from app that started it (the redirected standard input
    > > stream is used for IPC). And now comes the strange part: if I add a new
    > > button to windows form and in the click action call some web service,
    > > the web service deadlocks!!!
    > >
    > > I wrote a simple demo application to demonstrate the problem.
    > >
    > > The TestWebServiceStrangePhenomenom code:
    > >
    > > public partial class Form1 : Form
    > > {
    > > public Form1()
    > > {
    > > InitializeComponent();
    > > }
    > >
    > > private void Form1_Load(object sender, EventArgs e)
    > > {
    > > new Thread( new ThreadStart( WaitForInput ) ).Start();
    > >
    > > // Give thread time to start...
    > > Thread.Sleep( 200 );
    > > }
    > >
    > > private void WaitForInput ()
    > > {
    > > Stream stdin = Console.OpenStandardInput();
    > > // Wait for input...
    > > int rv = stdin.ReadByte();
    > > }
    > >
    > > private void buttonHelloWorld_Click(object sender, EventArgs e)
    > > {
    > > // !!! Deadlock HERE !!!
    > > HelloWorld.Service hw = new
    > > TestWebService.HelloWorld.Service();
    > > string str = hw.HelloWorld();
    > >
    > > MessageBox.Show( str );
    > > }
    > > }
    > >
    > >
    > > For the web service I used the default ASP.Net Web Service sample
    > > (HelloWorld) that is automaticaly generated within VS2005.
    > >
    > > And also the code for starting the TestWebServiceStrangePhenomenom
    > > (another project):
    > >
    > > public partial class mainForm : Form
    > > {
    > > public mainForm()
    > > {
    > > InitializeComponent();
    > > }
    > >
    > > private void buttonBrowse_Click(object sender, EventArgs e)
    > > {
    > > if ( openFileDialog.ShowDialog() == DialogResult.OK )
    > > textBoxPath.Text = openFileDialog.FileName;
    > > }
    > >
    > > Process process = new Process();
    > >
    > > private void buttonRun_Click(object sender, EventArgs e)
    > > {
    > > process.StartInfo.UseShellExecute = false;
    > > process.StartInfo.RedirectStandardInput = true;
    > > process.StartInfo.FileName = textBoxPath.Text;
    > > process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    > > process.Start();
    > > }
    > > }
    > >
    > > If the TestWebServiceStrangePhenomenom has not got the input stream
    > > redirected, than the web service will work!
    > >
    > >
     
    Crnjan, Sep 12, 2006
    #3
  4. Crnjan

    Crnjan Guest

    For the sake of clearety I have to state that I waited for 1 (one!)
    whole hour to continue executing without any success. Because this is a
    very simple web service returning only a simple string and running on
    same machine I think that is more than enought ïŠ.

    I can also provide VS2005 projects if someone is interested in trying
    the strange phenomena for himself, just send me an e-mail and I wil
    send the projects to you.

    Hope for a solution soon,
    Crnjan

    Crnjan je napisal:
    > No. The executing stops within web service's constructor. The web
    > service (Hello World) is running on local machine so their in NO way
    > that web service could deadlock. The execution simply stops. If the
    > same web service is invoked from other application the web service
    > works without problems. The web service also works if it is invoked
    > from same application if the standard input is not redirected as stated
    > above.
    >
    > So to repeat the scenario:
    >
    > If the TestWebServiceStrangePhenomenom application is simply run (for
    > example from VS2005 environment) than there is NO problem executing web
    > service.
    >
    > If the TestWebServiceStrangePhenomenom application is run from other
    > application that redirects TestWebServiceStrangePhenomenom's standard
    > input, than web service doesn't work. Its execution stops when
    > executing constructor:
    >
    > HelloWorld.Service hw = new TestWebService.HelloWorld.Service();
    >
    >
    > Hope I was clear enough,
    > crnjan
    >
    >
    > Peter je napisal:
    > > What do you mean by "deadlock". There's nothing in click handler that
    > > "deadlocks" in the normal mutli-threaded use of the work.
    > >
    > > Do you simply mean your application stops responding to user input while
    > > waiting for the web service operation to execute?
    > >
    > > --
    > > Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
    > > http://www.peterRitchie.com/blog/
    > > Microsoft MVP, Visual Developer - Visual C#
    > >
    > >
    > > "Crnjan" wrote:
    > >
    > > > Hello!
    > > >
    > > > I recently found a strange phenomenon. I am using a simple Windows
    > > > Application based application written in C# (lets name it
    > > > TestWebServiceStrangePhenomenom). The TestWebServiceStrangePhenomenom
    > > > application is started from another application which also redirects
    > > > standard input from TestWebServiceStrangePhenomenom. The
    > > > TestWebServiceStrangePhenomenom creates a new thread and within it,
    > > > waits for input from app that started it (the redirected standard input
    > > > stream is used for IPC). And now comes the strange part: if I add a new
    > > > button to windows form and in the click action call some web service,
    > > > the web service deadlocks!!!
    > > >
    > > > I wrote a simple demo application to demonstrate the problem.
    > > >
    > > > The TestWebServiceStrangePhenomenom code:
    > > >
    > > > public partial class Form1 : Form
    > > > {
    > > > public Form1()
    > > > {
    > > > InitializeComponent();
    > > > }
    > > >
    > > > private void Form1_Load(object sender, EventArgs e)
    > > > {
    > > > new Thread( new ThreadStart( WaitForInput ) ).Start();
    > > >
    > > > // Give thread time to start...
    > > > Thread.Sleep( 200 );
    > > > }
    > > >
    > > > private void WaitForInput ()
    > > > {
    > > > Stream stdin = Console.OpenStandardInput();
    > > > // Wait for input...
    > > > int rv = stdin.ReadByte();
    > > > }
    > > >
    > > > private void buttonHelloWorld_Click(object sender, EventArgs e)
    > > > {
    > > > // !!! Deadlock HERE !!!
    > > > HelloWorld.Service hw = new
    > > > TestWebService.HelloWorld.Service();
    > > > string str = hw.HelloWorld();
    > > >
    > > > MessageBox.Show( str );
    > > > }
    > > > }
    > > >
    > > >
    > > > For the web service I used the default ASP.Net Web Service sample
    > > > (HelloWorld) that is automaticaly generated within VS2005.
    > > >
    > > > And also the code for starting the TestWebServiceStrangePhenomenom
    > > > (another project):
    > > >
    > > > public partial class mainForm : Form
    > > > {
    > > > public mainForm()
    > > > {
    > > > InitializeComponent();
    > > > }
    > > >
    > > > private void buttonBrowse_Click(object sender, EventArgs e)
    > > > {
    > > > if ( openFileDialog.ShowDialog() == DialogResult.OK )
    > > > textBoxPath.Text = openFileDialog.FileName;
    > > > }
    > > >
    > > > Process process = new Process();
    > > >
    > > > private void buttonRun_Click(object sender, EventArgs e)
    > > > {
    > > > process.StartInfo.UseShellExecute = false;
    > > > process.StartInfo.RedirectStandardInput = true;
    > > > process.StartInfo.FileName = textBoxPath.Text;
    > > > process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    > > > process.Start();
    > > > }
    > > > }
    > > >
    > > > If the TestWebServiceStrangePhenomenom has not got the input stream
    > > > redirected, than the web service will work!
    > > >
    > > >
     
    Crnjan, Sep 12, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leo Muller
    Replies:
    2
    Views:
    449
    Paul Glavich [MVP - ASP.NET]
    Jun 16, 2004
  2. Mohammad S Khan

    JDBC - Constructing a query realtime

    Mohammad S Khan, Oct 31, 2003, in forum: Java
    Replies:
    0
    Views:
    418
    Mohammad S Khan
    Oct 31, 2003
  3. Replies:
    3
    Views:
    3,316
    isitmeorthey
    Aug 29, 2005
  4. Archimede

    concurrency constructing objects

    Archimede, Nov 25, 2005, in forum: Java
    Replies:
    5
    Views:
    436
    Chris Uppal
    Dec 1, 2005
  5. Leo Violette
    Replies:
    0
    Views:
    1,098
    Leo Violette
    Apr 17, 2009
Loading...

Share This Page