Solved

Server busy dialog Box winform c#

Posted on 2011-03-15
13
1,005 Views
Last Modified: 2012-05-11
Hi..
  i am getting server busy dialog box when a oracle procedure is run from winform c#. I need solution to supress this dialog Box or how can i close this dialog box through programtically.

public static void f()
{
 -- here runs oracle procedure    // here i get server busy dialog Box.
 
}

Need Urgent Solution.


Thanks in Advance.

0
Comment
Question by:rnsr
  • 7
  • 5
13 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
Comment Utility
you can solve this problem by using multi threading

and check this similar thread

http://www.experts-exchange.com/Microsoft/Development/Q_26861022.html
0
 

Author Comment

by:rnsr
Comment Utility
Not the suitable answer.......................
0
 

Author Comment

by:rnsr
Comment Utility
short code

My code is something like this --

button click
{
      string a;
  string b;

  datatable  k =   function (a,b) // this invokes oracle procedure. this displays "server busy dialog
 
 foreach (DataRow pDataRow in k.Rows)
  {
      .....
      ....
  }

......
}

}

0
 
LVL 33

Expert Comment

by:Todd Gerbert
Comment Utility
Just because you don't like the answer doesn't make it wrong. :)

According to the link that kalpesh posted you may need to run your function on another thread - I'm not entirely sure that's true, but it couldn't hurt to try and is not too difficult to implement.  If you want to post your actual code, we may be able to help guide you in doing that.
0
 
LVL 33

Expert Comment

by:Todd Gerbert
Comment Utility
Maybe this will help - I don't have access to an Oracle server, so I have a SqlConnection in here just for demonstration; the rest of the logic still applies (you'd just change the SQL statements to their Oracle counterparts).

using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
	public partial class Form1 : Form
	{
		private BackgroundWorker getDataTableThread;

		public Form1()
		{
			InitializeComponent();

			getDataTableThread = new BackgroundWorker();
			getDataTableThread.WorkerReportsProgress = false;
			getDataTableThread.WorkerSupportsCancellation = false;
			getDataTableThread.DoWork += new DoWorkEventHandler(getDataTableThread_DoWork);
			getDataTableThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(getDataTableThread_RunWorkerCompleted);
		}

		void getDataTableThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
			// The background thread has completed
			// Get the result, cast it to a DataTable object,
			// populate the list box with results
			DataTable results = (DataTable)e.Result;
			foreach (DataRow row in results.Rows)
				ResultsListBox.Items.Add((string)row["SalesOrderNumber"]);
			
			// re-enable the button and list box
			// and disable the wait cursor
			GetDataTableButton.Enabled = true;
			ResultsListBox.Enabled = true;
			this.UseWaitCursor = false;

			
		}

		void getDataTableThread_DoWork(object sender, DoWorkEventArgs e)
		{
			// The code in this event handler will be run on a background thread
			// when RunWorkerAsync() is called

			DataTable dt = new DataTable();

			using (SqlConnection cnx = new SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=AdventureWorks;Integrated Security=yes"))
			{
				cnx.Open();
				using (SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT SalesOrderNumber FROM Sales.SalesOrderHeader", cnx))
				{
					dataAdapter.Fill(dt);
				}
				cnx.Close();
			}

			e.Result = dt; // Save the data table to e.Result, so we can get at it in the main thread
		}

		private void GetDataTableButton_Click(object sender, EventArgs e)
		{
			// Disable the button and list box, and use the wait cursor,
			// until the background thread getting the data table finishes
			GetDataTableButton.Enabled = false;
			ResultsListBox.Enabled = false;
			this.UseWaitCursor = true;

			// Start the background thread to get the data table
			getDataTableThread.RunWorkerAsync();
		}
	}
}

Open in new window

0
 

Author Comment

by:rnsr
Comment Utility
Hellow,
   Thanks for reply. here is my code when i click button --
  private void button1_Click(object sender, EventArgs e)
        {
           
          //TESTBOX1.TEXT IS DATE ENTRY
            axMappointControl1.Visible = false;
            axMappointControl1.NewMap (MapPoint.GeoMapRegion.geoMapNorthAmerica);
            axMappointControl1.Units = MapPoint.GeoUnits.geoMiles ;
           
             objMap = axMappointControl1.ActiveMap;
             objMap.Parent.PaneState = MapPoint.GeoPaneState.geoPaneRoutePlanner;
           
            int counter = 0;
             string aUpdLatLong;
         
           try
            {
                dt = DataAccess.DataAccess_Ora.customer_trip("myplan", textBox1.Text.ToString());
                             
               foreach (DataRow dataRow in dt.Rows)
                {       dataRow["s_GRID_LAT"] = latlongvalue[0].ToString();
                        dataRow["s_GRID_LONG"] = latlongvalue[1].ToString();
                        dataRow["e_GRID_LAT"] = latlongvalue[0].ToString();
                        dataRow["e_GRID_LONG"] = latlongvalue[1].ToString();
                       
                   
                   
                    double dist = loc.DistanceTo(axMappointControl1.ActiveMap.GetLocation(Convert.ToDouble(dataRow["e_GRID_LAT"].ToString()), Convert.ToDouble(dataRow["e_GRID_LONG"].ToString()), 1));
                    dataRow["est_distance"] = dist.ToString();
                                //
                    // Below function takes time. below function invokes procedure calculatebid  
                   // below function takes 9 seconds to execute. THE RECORDS ARE MORE THAN 10,000 TO GET PROCESSED.
                   // AND IT DISPLAYES "SERVER BUSY" DIALOG BOX.
                   // THREAD,TIMER HAD NOT WORKED FOR ME.
                   // I NEED THAT SERVER BUSY DIALOG SHOULD NOT BE DISPLAYED.
                    Datatable dtt = DataAccess.DataAccess_Ora.calculatebid("myplan", textBox1.Text.ToString(), dataRow["id"].ToString(), firstrun, dataRow["est_distance"].ToString(),  dataRow["s_GRID_LAT"].ToString(), dataRow["s_GRID_LONG"].ToString(), dataRow["e_GRID_LAT"].ToString(), dataRow["s_GRID_LONG"].ToString());
                    // above function takes time
 
                   foreach (datarow dr in dtt.rows)
                    {
                            // do anything with the record stored in dtt datatable.
                     }
                   
                    Application.DoEvents();
               }
                dt.AcceptChanges();
                 dt.Dispose();
                objMap.Saved = true;
             }
            catch (Exception ex)
            {
                textBox1.Text = ex.ToString();
            }
        }


some unnecessay code i had removed like progress bar,mappoint code, etc.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 33

Expert Comment

by:Todd Gerbert
Comment Utility
Can you post the entire form's code?  More than the contents of the button's click event handler will need to be changed, and when you're using threads things like progress bars become important.
0
 

Author Comment

by:rnsr
Comment Utility
Hi,
   right now i am at home and the project is at my office . I will post code  tomorrow from office. My requirement is Urgent and I hope i will get suitable support form ur side.

Thanks in Advance.
0
 
LVL 33

Expert Comment

by:Todd Gerbert
Comment Utility
I wasn't really able to follow your code well since I'm not familiar with MapPoint stuff, but this is the general idea. Since I'm not sure what does what in your code, this may not run - you will probably have to fix this up a good bit.

The basic idea is that clicking the button will disable that button (so the user can't click it a second time while the background thread's still running), and show the wait cursor (so the user knows something's going on), then start the background thread.  The code inside the BackgroundWorker's "DoWork" event is what gets run on the background thread, and is started when you call BackgroundWorker.RunWorkerAsync().

I just moved most of the code you had in button1_Click into the background thread - some of it stayed in button1_Click because I believe it may refer to controls on the form, and background threads can't access from controls. For that reason you also have to use the ReportProgress() method and ProgressChanged event to do things like update a progress bar (the ProgressChanged event will run on the main thread, not the background one) - and also the reason we use the arguments in the various events to pass data into and out of the background thread.

When the thread finishes the WorkerCompleted event is raised, where we can re-enable the button and turn off the wait cursor.

You also need to be sure you're not changing variables in the background thread and the main thread at the same time.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();

			// Setup the background worker
			backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
			backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
			backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
			backgroundWorker1.WorkerReportsProgress = true;
			backgroundWorker1.WorkerSupportsCancellation = false;
		}

		void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
		{
			// This event is raised in the main thread, not the background
			// thread, so it's safe to update controls on the form here
			progressBar1.Increment();
		}

		void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
			// The background thread is done...
			// if there was an exception we set it in DoWorkEventArgs.Result
			// check if that's set
			if (!String.IsNullOrEmpty(e.Result as string))
			{
				MessageBox.Show("An exception occurred.");
				textBox1.Text = (string)e.Result;
			}

			// Turn off the wait cursor and re-enable the button
			button1.Enabled = true;
			this.UseWaitCursor = false;
		}

		void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
		{
			// This code runs in a background thread

			// Get the argument that was passed in (the textBox1 text)
			string textBox1Value = (string)e.Argument;

			try
			{
				dt = DataAccess.DataAccess_Ora.customer_trip("myplan", textBox1Value);

				foreach (DataRow dataRow in dt.Rows)
				{
					dataRow["s_GRID_LAT"] = latlongvalue[0].ToString();
					dataRow["s_GRID_LONG"] = latlongvalue[1].ToString();
					dataRow["e_GRID_LAT"] = latlongvalue[0].ToString();
					dataRow["e_GRID_LONG"] = latlongvalue[1].ToString();

					// Since you can't update controls on the form from the background thread
					// if you need to update a progress bar or such, use the ReportProgess method
					backgroundWorker1.ReportProgress(10);

					double dist = loc.DistanceTo(axMappointControl1.ActiveMap.GetLocation(Convert.ToDouble(dataRow["e_GRID_LAT"].ToString()), Convert.ToDouble(dataRow["e_GRID_LONG"].ToString()), 1));
					dataRow["est_distance"] = dist.ToString();
					//
					// Below function takes time. below function invokes procedure calculatebid  
					// below function takes 9 seconds to execute. THE RECORDS ARE MORE THAN 10,000 TO GET PROCESSED.
					// AND IT DISPLAYES "SERVER BUSY" DIALOG BOX.
					// THREAD,TIMER HAD NOT WORKED FOR ME.
					// I NEED THAT SERVER BUSY DIALOG SHOULD NOT BE DISPLAYED.
					Datatable dtt = DataAccess.DataAccess_Ora.calculatebid("myplan", textBox1Value, dataRow["id"].ToString(), firstrun, dataRow["est_distance"].ToString(), dataRow["s_GRID_LAT"].ToString(), dataRow["s_GRID_LONG"].ToString(), dataRow["e_GRID_LAT"].ToString(), dataRow["s_GRID_LONG"].ToString());
					// above function takes time

					foreach (datarow dr in dtt.rows)
					{
						// do anything with the record stored in dtt datatable.
					}
				}
				dt.AcceptChanges();
				dt.Dispose();
				objMap.Saved = true;
			}
			catch (Exception ex)
			{
				// Can't access text box from background thread
				// so return a value in the DoWorkEventArgs
				e.Result = ex.Message;
			}
		}

		private void button1_Click(object sender, EventArgs e)
		{
			// Disable the button and show the wait cursor
			button1.Enabled = false;
			this.UseWaitCursor = true;

			//TESTBOX1.TEXT IS DATE ENTRY
			axMappointControl1.Visible = false;
			axMappointControl1.NewMap(MapPoint.GeoMapRegion.geoMapNorthAmerica);
			axMappointControl1.Units = MapPoint.GeoUnits.geoMiles;

			objMap = axMappointControl1.ActiveMap;
			objMap.Parent.PaneState = MapPoint.GeoPaneState.geoPaneRoutePlanner;

			int counter = 0;
			string aUpdLatLong;

			// Start the background thread
			// You can't access controls on the form from
			// the background thread, so pass textBox1.Text
			// as an argument to the background thread
			backgroundWorker1.RunWorkerAsync(textBox1.Text);
		}
	}
}

Open in new window

0
 

Author Comment

by:rnsr
Comment Utility
Hi,
   here is my code --

       
           ProgressBar pbar = new ProgressBar();
            pBar.Name = "progressBar1";
            pBar.Width = 260;
            pBar.Height = 15;
            pBar.Minimum = 0;
 private void button2_Click(object sender, EventArgs e)
        {
         
            lblCountervalue.Text = " ";
            lblrouteId.Text = " ";
            counter = 0;
            pcounter = 0;
            tdate = dateTimePicker1.Value.Date.ToShortDateString();
            pBar.Location = new System.Drawing.Point(70, 120);
            this.splitContainer1.Panel2.Controls.Add(this.pBar);
            textBox1.Text = tdate;
            pBar.Value = 0;
            char aUpdLatLong;
            aUpdLatLong = 'N';
           
            try
            {
                dt = DataAccess.DataAccess_Ora.customer_trip(connectserver, textBox1.Text.ToString());// server name and date parameter passed
                 pBar.Maximum = dt.Rows.Count;
                foreach (DataRow dataRow in dt.Rows)
                {
                   
                   
                        dataRow["s_GRID_LAT"] = latlongvalue[0].ToString();
                        dataRow["s_GRID_LONG"] = latlongvalue[1].ToString();
                        dataRow["e_GRID_LAT"] = latlongvalue[0].ToString();
                        dataRow["e_GRID_LONG"] = latlongvalue[1].ToString();
                   
                    String aDistanceTime;
                    Double aGridLat1 = Convert.ToDouble(dataRow["s_GRID_LAT"].ToString());
                    Double aGridLong1 = Convert.ToDouble(dataRow["s_GRID_LONG"].ToString());
                    Double aGridLat2 = Convert.ToDouble(dataRow["e_GRID_LAT"].ToString());
                    Double aGridLong2 = Convert.ToDouble(dataRow["e_GRID_LONG"].ToString());
                    aDistanceTime = mappointctl.getDistance_ll(ref aGridLat1, ref aGridLong1, ref aGridLat2, ref aGridLong2);// found in CallCenter_Trips.cs
                    Double tims = Math.Round(double.Parse(aDistanceTime.Split('^')[1]), 2); // travel time calculation
                    Double distime = Math.Round(double.Parse(aDistanceTime.Split('^')[0]), 2);  // distance calculation
                    dataRow["drive_time"] = tims.ToString();
                    if (Convert.ToDouble(dataRow["est_distance"].ToString()) == 0)
                    {
                        dataRow["est_distance"] = distime.ToString();
                    }
                    if (Convert.ToDouble(dataRow["est_distance"].ToString()) > 0)
                    {
                        //Stopwatch sw = Stopwatch.StartNew();
                            dtt = DataAccess.DataAccess_Ora.calculate_route(connectserver, tdate, dataRow["routeid"].ToString(), firstrun, dataRow["est_distance"].ToString(), dataRow["drive_time"].ToString(), dataRow["s_GRID_LAT"].ToString(), dataRow["s_GRID_LONG"].ToString(), dataRow["e_GRID_LAT"].ToString(), dataRow["e_GRID_LONG"].ToString(), aUpdLatLong);
                        // here displays "server busy dialog box
                           //sw.Stop();
                        if (dtt.Rows.Count > 0)
                        {
                            foreach (DataRow pDataRow in dtt.Rows)
                            {
                                if (pDataRow["routeid"].ToString().Length > 0)
                                {
                                    counter++;
                                    lblCountervalue.Text = counter.ToString();  // this displays value on winform
                                    lblrouteId.Text = pDataRow["routeid"].ToString();  // this displays route num on winform
                                }

                                Application.DoEvents();
                            }
                        }
                    }
                    pcounter++;
                    pBar.Value = pcounter;
                   
                }
               
                dt.Dispose();
               
            }
            catch (Exception ex)
            {
                txtbox1.text = ex.Message;
         
            }

        }
       


waiting for comments. Thanks.
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
Comment Utility
Have a look at the code examples I put in my comments http:#a35141016 and http:#a35144509, and see if you can't adapt the BackgroundWorker for use in your project.

Below is another idea, that runs just that one long-running method in a background thread.

Remember: you can't access Windows Forms controls from any kind of background thread.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

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

		private void button1_Click(object sender, EventArgs e)
		{
			//TESTBOX1.TEXT IS DATE ENTRY
			axMappointControl1.Visible = false;
			axMappointControl1.NewMap(MapPoint.GeoMapRegion.geoMapNorthAmerica);
			axMappointControl1.Units = MapPoint.GeoUnits.geoMiles;

			objMap = axMappointControl1.ActiveMap;
			objMap.Parent.PaneState = MapPoint.GeoPaneState.geoPaneRoutePlanner;

			int counter = 0;
			string aUpdLatLong;

			try
			{
				dt = DataAccess.DataAccess_Ora.customer_trip("myplan", textBox1.Text.ToString());

				foreach (DataRow dataRow in dt.Rows)
				{
					dataRow["s_GRID_LAT"] = latlongvalue[0].ToString();
					dataRow["s_GRID_LONG"] = latlongvalue[1].ToString();
					dataRow["e_GRID_LAT"] = latlongvalue[0].ToString();
					dataRow["e_GRID_LONG"] = latlongvalue[1].ToString();



					double dist = loc.DistanceTo(axMappointControl1.ActiveMap.GetLocation(Convert.ToDouble(dataRow["e_GRID_LAT"].ToString()), Convert.ToDouble(dataRow["e_GRID_LONG"].ToString()), 1));
					dataRow["est_distance"] = dist.ToString();
					// 
					// Below function takes time. below function invokes procedure calculatebid  
					// below function takes 9 seconds to execute. THE RECORDS ARE MORE THAN 10,000 TO GET PROCESSED.
					// AND IT DISPLAYES "SERVER BUSY" DIALOG BOX.
					// THREAD,TIMER HAD NOT WORKED FOR ME.
					// I NEED THAT SERVER BUSY DIALOG SHOULD NOT BE DISPLAYED.
					
					// Run just this method in a separate thread
					DataTable dtt = null;
					Thread t = new Thread(delegate(string textBoxValue)
						{
							dtt = DataAccess.DataAccess_Ora.calculatebid("myplan", textBoxValue, dataRow["id"].ToString(), firstrun, dataRow["est_distance"].ToString(), dataRow["s_GRID_LAT"].ToString(), dataRow["s_GRID_LONG"].ToString(), dataRow["e_GRID_LAT"].ToString(), dataRow["s_GRID_LONG"].ToString());
						});
					t.IsBackground = true;
					t.Start(textBox1.Text);

					// The Join method will wait for the thread to finish, but will allow
					// your application to continue to process Windows/COM messages, so
					// it won't appear "hung" and might avoid the dialog you're getting
					// You can also have it timeout, so if the thread doesn't finish
					// in a certain amount of time you can try to kill it or something
					t.Join(0;
					// above function takes time

					foreach (datarow dr in dtt.rows)
					{
						// do anything with the record stored in dtt datatable.
					}

					Application.DoEvents();
				}
				dt.AcceptChanges();
				dt.Dispose();
				objMap.Saved = true;
			}
			catch (Exception ex)
			{
				textBox1.Text = ex.ToString();
			}

		}
	}
}

Open in new window


I would also be curious to know what the method DataAccess.DataAccess_Ora.calculatebid does, too.
0
 

Author Comment

by:rnsr
Comment Utility
I hope the last solution will work. let me try it out  .
0
 

Author Closing Comment

by:rnsr
Comment Utility
Thanks a lot. the solution was very useful. also it let me understand the concept of Thread.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is a fairly complicated script that will install the required prerequisites to install SCCM 2012 R2 on a server.  It was designed under the functional model in order to compartmentalize each step required, reducing the overall complexity.  The …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now