Click here to Skip to main content
15,894,343 members
Home / Discussions / C#
   

C#

 
GeneralRe: Turning of the monitors Pin
Heath Stewart29-Jul-04 9:50
protectorHeath Stewart29-Jul-04 9:50 
GeneralRe: Turning of the monitors Pin
PrebKlok30-Jul-04 0:50
PrebKlok30-Jul-04 0:50 
GeneralRe: Turning of the monitors Pin
Heath Stewart30-Jul-04 3:33
protectorHeath Stewart30-Jul-04 3:33 
GeneralRe: Turning of the monitors Pin
PrebKlok30-Jul-04 4:01
PrebKlok30-Jul-04 4:01 
GeneralRe: Turning of the monitors Pin
Heath Stewart30-Jul-04 4:23
protectorHeath Stewart30-Jul-04 4:23 
GeneralRe: Turning of the monitors Pin
PrebKlok30-Jul-04 4:53
PrebKlok30-Jul-04 4:53 
GeneralRe: Turning of the monitors Pin
Heath Stewart30-Jul-04 5:01
protectorHeath Stewart30-Jul-04 5:01 
GeneralAsynchronous Pin
sreejith ss nair29-Jul-04 2:17
sreejith ss nair29-Jul-04 2:17 
hi there,

I developed a small application which will clean up all record(say 4000 or 5000 record) from a dummy table and will insert the updated version of that cleaned record from some other table. This operation is happening oncloseing event handler of that perticular application.

I am using asynchronous programming style for inserting records and synchronous for deletion.

When user click on Exit button, he is actually starting the above mentioned operation.The main problem is he can exit from application once the deletion(synchronous) completes. Here that insertion may or may not on progress depending upon the record size to insert. Why cause insertion is in asynchronous fasion.

In this senario my insertion operation will terminate with inserting few records from actuall collection and will give error say "Communication Error".because the application is closed.

one more thing is i can only do this much operation on the time of application exit not before.


i am including main part of my code block.


//required namespaces

namespace PlanningBoardSystem.GUI
{
public delegate void DataRowInsertionDel(DataRow Dtr);
public class BatchRecordInsertion
{

string DSN=ConfigurationSettings.AppSettings["sourcename"].ToString();
AsaTransaction Astrns;
string Uid="dft";
string Pwd="dft";
AsaConnection Conn;
private DataRow[] Dtable;

public void MyCallBack(IAsyncResult Iar)
{
DataRowInsertionDel DRID=Iar.AsyncState as DataRowInsertionDel;
DRID.EndInvoke(Iar);
}
public void InsertRecord(DataRow Dtr)
{
try
{
//Astrns=Conn.BeginTransaction();
string InsertCmd="Insert into tem values('"+Dtr["process_id"]+"','"+Dtr["record_type"]+"','"+Dtr["process_dec"]+"')";
AsaCommand Asa=new AsaCommand(InsertCmd,Conn);
//Asa.Transaction=Astrns;
Asa.ExecuteNonQuery();
}
catch(Exception Ex)
{
//Astrns.Rollback();
MessageBox.Show(Ex.Message.ToString());
}
}

public BatchRecordInsertion(DataRow[] Dtable)
{

this.Dtable=Dtable;
try
{
Conn=new AsaConnection("Data Source='"+DSN+"'; uid='"+Uid+"'; pwd='"+Pwd+"'");
Conn.Open();
string Delcmd="Delete from tem";
AsaCommand Asa=new AsaCommand(Delcmd,Conn);
//Asa.Transaction=Astrns;
Asa.ExecuteNonQuery();
}
catch(Exception Ex)
{
MessageBox.Show("Error While Opening Database Connection","Database Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}

DataRowInsertionDel InsertDel=new DataRowInsertionDel(InsertRecord);
AsyncCallback AsCall=new AsyncCallback(MyCallBack);
for(int j=0;j<<1000;j++)

for(int i=0;i<<5;i++)
{
DataRow Dtr=Dtable[i];
IAsyncResult IAR=InsertDel.BeginInvoke(Dtr,null,null);
}


}
}
}


//here i used one outer loop. don't worry about that. i have only five record in
Dtable. i want few more record.that's why i used that loop//



" How will i handle this sort of situation ?"

" how can i ensure all insertion operations are completed or not " ?

" How i will hold the exit operation upto the completion of all insertion process " ?



"If you know efficient way than this idea of inserting bulk amount of records(no validation required) while keeping performance in mind. Then tell me how ? "
Blush | :O



********************
S r e e j i t h N a i r
Bangalore - India
********************
GeneralRe: Asynchronous Pin
SOCM_FP_CPP29-Jul-04 3:05
SOCM_FP_CPP29-Jul-04 3:05 
GeneralRe: Asynchronous Pin
Heath Stewart29-Jul-04 5:02
protectorHeath Stewart29-Jul-04 5:02 
GeneralRe: Asynchronous Pin
sreejith ss nair29-Jul-04 20:29
sreejith ss nair29-Jul-04 20:29 
GeneralRe: Asynchronous Pin
Heath Stewart30-Jul-04 3:19
protectorHeath Stewart30-Jul-04 3:19 
GeneralRe: Asynchronous Pin
sreejith ss nair30-Jul-04 3:36
sreejith ss nair30-Jul-04 3:36 
GeneralRe: Asynchronous Pin
Heath Stewart30-Jul-04 4:11
protectorHeath Stewart30-Jul-04 4:11 
GeneralRe: Asynchronous Pin
sreejith ss nair30-Jul-04 4:21
sreejith ss nair30-Jul-04 4:21 
GeneralRe: Asynchronous Pin
Heath Stewart30-Jul-04 4:57
protectorHeath Stewart30-Jul-04 4:57 
GeneralRe: Asynchronous Pin
sreejith ss nair30-Jul-04 3:36
sreejith ss nair30-Jul-04 3:36 
GeneralRe: Asynchronous Pin
Tom Larsen29-Jul-04 5:42
Tom Larsen29-Jul-04 5:42 
GeneralQuestion on Porting Pin
SatyaDY29-Jul-04 0:40
SatyaDY29-Jul-04 0:40 
GeneralRe: Question on Porting Pin
Colin Angus Mackay29-Jul-04 0:45
Colin Angus Mackay29-Jul-04 0:45 
GeneralRe: Question on Porting Pin
SatyaDY29-Jul-04 17:54
SatyaDY29-Jul-04 17:54 
GeneralRe: Question on Porting Pin
Colin Angus Mackay29-Jul-04 20:41
Colin Angus Mackay29-Jul-04 20:41 
Generalseem to have a blackout Pin
Stephan Wright28-Jul-04 23:01
Stephan Wright28-Jul-04 23:01 
GeneralRe: seem to have a blackout Pin
Colin Angus Mackay28-Jul-04 23:38
Colin Angus Mackay28-Jul-04 23:38 
GeneralRe: seem to have a blackout Pin
Stephan Wright29-Jul-04 23:30
Stephan Wright29-Jul-04 23:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.