rnsr
asked on
Server busy dialog Box winform c#
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.
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.
ASKER
Not the suitable answer.................... ...
ASKER
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)
{
.....
....
}
......
}
}
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)
{
.....
....
}
......
}
}
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.
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.
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();
}
}
}
ASKER
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.geo MapNorthAm erica);
axMappointControl1.Units = MapPoint.GeoUnits.geoMiles ;
objMap = axMappointControl1.ActiveM ap;
objMap.Parent.PaneState = MapPoint.GeoPaneState.geoP aneRoutePl anner;
int counter = 0;
string aUpdLatLong;
try
{
dt = DataAccess.DataAccess_Ora. customer_t rip("mypla n", 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(axMappointC ontrol1.Ac tiveMap.Ge tLocation( Convert.To Double(dat aRow["e_GR ID_LAT"].T oString()) , Convert.ToDouble(dataRow[" e_GRID_LON G"].ToStri ng()), 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. calculateb id("myplan ", textBox1.Text.ToString(), dataRow["id"].ToString(), firstrun, dataRow["est_distance"].To String(), dataRow["s_GRID_LAT"].ToSt ring(), dataRow["s_GRID_LONG"].ToS tring(), dataRow["e_GRID_LAT"].ToSt ring(), dataRow["s_GRID_LONG"].ToS tring());
// 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.
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
axMappointControl1.NewMap (MapPoint.GeoMapRegion.geo
axMappointControl1.Units = MapPoint.GeoUnits.geoMiles
objMap = axMappointControl1.ActiveM
objMap.Parent.PaneState = MapPoint.GeoPaneState.geoP
int counter = 0;
string aUpdLatLong;
try
{
dt = DataAccess.DataAccess_Ora.
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(axMappointC
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.
// 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.
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.
ASKER
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.
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.
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.RunWorker Async().
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.
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.RunWorker
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);
}
}
}
ASKER
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 .ToShortDa teString() ;
pBar.Location = new System.Drawing.Point(70, 120);
this.splitContainer1.Panel 2.Controls .Add(this. pBar);
textBox1.Text = tdate;
pBar.Value = 0;
char aUpdLatLong;
aUpdLatLong = 'N';
try
{
dt = DataAccess.DataAccess_Ora. customer_t rip(connec tserver, 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 "].ToStrin g());
Double aGridLong1 = Convert.ToDouble(dataRow[" s_GRID_LON G"].ToStri ng());
Double aGridLat2 = Convert.ToDouble(dataRow[" e_GRID_LAT "].ToStrin g());
Double aGridLong2 = Convert.ToDouble(dataRow[" e_GRID_LON G"].ToStri ng());
aDistanceTime = mappointctl.getDistance_ll (ref aGridLat1, ref aGridLong1, ref aGridLat2, ref aGridLong2);// found in CallCenter_Trips.cs
Double tims = Math.Round(double.Parse(aD istanceTim e.Split('^ ')[1]), 2); // travel time calculation
Double distime = Math.Round(double.Parse(aD istanceTim e.Split('^ ')[0]), 2); // distance calculation
dataRow["drive_time"] = tims.ToString();
if (Convert.ToDouble(dataRow[ "est_dista nce"].ToSt ring()) == 0)
{
dataRow["est_distance"] = distime.ToString();
}
if (Convert.ToDouble(dataRow[ "est_dista nce"].ToSt ring()) > 0)
{
//Stopwatch sw = Stopwatch.StartNew();
dtt = DataAccess.DataAccess_Ora. calculate_ route(conn ectserver, tdate, dataRow["routeid"].ToStrin g(), firstrun, dataRow["est_distance"].To String(), dataRow["drive_time"].ToSt ring(), dataRow["s_GRID_LAT"].ToSt ring(), dataRow["s_GRID_LONG"].ToS tring(), dataRow["e_GRID_LAT"].ToSt ring(), dataRow["e_GRID_LONG"].ToS tring(), aUpdLatLong);
// here displays "server busy dialog box
//sw.Stop();
if (dtt.Rows.Count > 0)
{
foreach (DataRow pDataRow in dtt.Rows)
{
if (pDataRow["routeid"].ToStr ing().Leng th > 0)
{
counter++;
lblCountervalue.Text = counter.ToString(); // this displays value on winform
lblrouteId.Text = pDataRow["routeid"].ToStri ng(); // 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.
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
pBar.Location = new System.Drawing.Point(70, 120);
this.splitContainer1.Panel
textBox1.Text = tdate;
pBar.Value = 0;
char aUpdLatLong;
aUpdLatLong = 'N';
try
{
dt = DataAccess.DataAccess_Ora.
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["
Double aGridLong1 = Convert.ToDouble(dataRow["
Double aGridLat2 = Convert.ToDouble(dataRow["
Double aGridLong2 = Convert.ToDouble(dataRow["
aDistanceTime = mappointctl.getDistance_ll
Double tims = Math.Round(double.Parse(aD
Double distime = Math.Round(double.Parse(aD
dataRow["drive_time"] = tims.ToString();
if (Convert.ToDouble(dataRow[
{
dataRow["est_distance"] = distime.ToString();
}
if (Convert.ToDouble(dataRow[
{
//Stopwatch sw = Stopwatch.StartNew();
dtt = DataAccess.DataAccess_Ora.
// here displays "server busy dialog box
//sw.Stop();
if (dtt.Rows.Count > 0)
{
foreach (DataRow pDataRow in dtt.Rows)
{
if (pDataRow["routeid"].ToStr
{
counter++;
lblCountervalue.Text = counter.ToString(); // this displays value on winform
lblrouteId.Text = pDataRow["routeid"].ToStri
}
Application.DoEvents();
}
}
}
pcounter++;
pBar.Value = pcounter;
}
dt.Dispose();
}
catch (Exception ex)
{
txtbox1.text = ex.Message;
}
}
waiting for comments. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I hope the last solution will work. let me try it out .
ASKER
Thanks a lot. the solution was very useful. also it let me understand the concept of Thread.
and check this similar thread
https://www.experts-exchange.com/questions/26861022/SERVER-BUSY-Dialog-box-in-winform-c.html