Click here to Skip to main content
15,908,455 members
Home / Discussions / C#
   

C#

 
QuestionSending email in asp.net (using C# & VS 2005) Pin
blskv24-Aug-09 8:51
blskv24-Aug-09 8:51 
AnswerRe: Sending email in asp.net (using C# & VS 2005) Pin
Hristo-Bojilov24-Aug-09 9:52
Hristo-Bojilov24-Aug-09 9:52 
Question[Message Deleted] Pin
neha_rai24-Aug-09 8:33
neha_rai24-Aug-09 8:33 
QuestionRe: 2-D array Pin
harold aptroot24-Aug-09 9:13
harold aptroot24-Aug-09 9:13 
AnswerRe: 2-D array Pin
neha_rai24-Aug-09 9:21
neha_rai24-Aug-09 9:21 
GeneralRe: 2-D array Pin
Luc Pattyn24-Aug-09 9:30
sitebuilderLuc Pattyn24-Aug-09 9:30 
AnswerRe: [Message Deleted] Pin
Luc Pattyn24-Aug-09 11:49
sitebuilderLuc Pattyn24-Aug-09 11:49 
QuestionProcesses (up to 4) accessing to "serial.log" file handling Pin
Blubbo24-Aug-09 8:23
Blubbo24-Aug-09 8:23 
I've had success having an individual (one at a time) to perform reading serial number from the file and increment by one and save the new number in this .log file.

However is that I'm trying to determine the best approach for each process to wait for the file access while one of the process is using the file. Once the file is ready for read/write, then the other process can use the file.

Sample code for each process (pretty much the same for the 4 processes:

--------

private void RunProcess1()
{
     while (fileHandle != IntPtr.Zero)
     {
          lblStatus1.BackColor = Color.Yellow;
          lblStatus1.Text = "Awaiting Accessing Serial file...";
          Application.DoEvents();

          for (int m = 0; m < 100000; m++)
               Application.DoEvents();
     }

     //do
     //{
          try
          {
               lblStatus1.BackColor = Color.Magenta;
               lblStatus1.Text = "Accessing Serial file";
               Application.DoEvents();
               FileStream filestream = new FileStream("serial.log", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None);
               fileHandle = filestream.Handle;
               StreamReader tr = new StreamReader(filestream);
               count = Convert.ToInt32(tr.ReadLine(), 10);
               lblSerial1.Text = count.ToString();
               tr.Close();

               lblStatus1.BackColor = Color.Lime;
               lblStatus1.Text = "Saving Serial file";
               Application.DoEvents();
                        
               filestream = new FileStream("serial.log", FileMode.Create, FileAccess.Write, FileShare.None);
               StreamWriter sw = new StreamWriter(filestream);
               sw.Write(++count);
               sw.Flush();
               lblStatus1.BackColor = Color.Green;
              
               for (int m = 0; m < 1000000; m++)
                    Application.DoEvents();
              
               sw.Close();

               lblStatus1.BackColor = defaultBackground;
               lblStatus1.Text = "Success!";
               Application.DoEvents();
               //timer1.Start();
               fileHandle = IntPtr.Zero;
          }
          catch (Exception err)
          {
               //timer1.Stop();
               //proc1Success = false;
          }

     //} while (proc1Success == false);
}
AnswerRe: Processes (up to 4) accessing to "serial.log" file handling Pin
Luc Pattyn24-Aug-09 9:31
sitebuilderLuc Pattyn24-Aug-09 9:31 
AnswerRe: Processes (up to 4) accessing to "serial.log" file handling (with pre-tags) Pin
Blubbo24-Aug-09 9:42
Blubbo24-Aug-09 9:42 
GeneralRe: Processes (up to 4) accessing to "serial.log" file handling (with pre-tags) Pin
Mycroft Holmes24-Aug-09 14:17
professionalMycroft Holmes24-Aug-09 14:17 
QuestionSetup & dependency error for officectrl.ocx Pin
NarVish24-Aug-09 6:53
NarVish24-Aug-09 6:53 
AnswerRe: Setup & dependency error for officectrl.ocx Pin
Saksida Bojan24-Aug-09 7:19
Saksida Bojan24-Aug-09 7:19 
GeneralRe: Setup & dependency error for officectrl.ocx Pin
NarVish24-Aug-09 7:24
NarVish24-Aug-09 7:24 
GeneralRe: Setup & dependency error for officectrl.ocx Pin
Saksida Bojan24-Aug-09 9:15
Saksida Bojan24-Aug-09 9:15 
QuestionCalling Form Buttonclick event from another file Pin
RS.Ratheesh24-Aug-09 6:41
RS.Ratheesh24-Aug-09 6:41 
AnswerRe: Calling Form Buttonclick event from another file Pin
Luc Pattyn24-Aug-09 6:52
sitebuilderLuc Pattyn24-Aug-09 6:52 
QuestionVirtual and Override problem Pin
bonzaiholding24-Aug-09 5:17
bonzaiholding24-Aug-09 5:17 
GeneralRe: Virtual and Override problem Pin
harold aptroot24-Aug-09 5:22
harold aptroot24-Aug-09 5:22 
AnswerRe: Virtual and Override problem Pin
Luc Pattyn24-Aug-09 5:47
sitebuilderLuc Pattyn24-Aug-09 5:47 
Questionint x = new int() where this will be stored ?? Pin
jpk42024-Aug-09 4:28
jpk42024-Aug-09 4:28 
AnswerRe: int x = new int() where this will be stored ?? PinPopular
Luc Pattyn24-Aug-09 4:58
sitebuilderLuc Pattyn24-Aug-09 4:58 
GeneralRe: int x = new int() where this will be stored ?? Pin
Richard MacCutchan25-Aug-09 9:41
mveRichard MacCutchan25-Aug-09 9:41 
GeneralRe: int x = new int() where this will be stored ?? Pin
Luc Pattyn25-Aug-09 15:30
sitebuilderLuc Pattyn25-Aug-09 15:30 
GeneralRe: int x = new int() where this will be stored ?? Pin
Richard MacCutchan26-Aug-09 3:19
mveRichard MacCutchan26-Aug-09 3:19 

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.