Click here to Skip to main content
15,920,110 members
Home / Discussions / C#
   

C#

 
GeneralExecuteNonQuery returns -1 Pin
creganc1-Sep-04 9:34
creganc1-Sep-04 9:34 
GeneralRe: ExecuteNonQuery returns -1 Pin
Charlie Williams1-Sep-04 10:31
Charlie Williams1-Sep-04 10:31 
GeneralRe: ExecuteNonQuery returns -1 Pin
creganc1-Sep-04 11:28
creganc1-Sep-04 11:28 
GeneralRe: ExecuteNonQuery returns -1 Pin
Charlie Williams1-Sep-04 12:26
Charlie Williams1-Sep-04 12:26 
GeneralRe: ExecuteNonQuery returns -1 Pin
creganc1-Sep-04 12:33
creganc1-Sep-04 12:33 
GeneralExpense Management tool in C# Pin
MT_SEA1-Sep-04 9:12
MT_SEA1-Sep-04 9:12 
GeneralDetermining if a file is locked by another process Pin
nhoellei1-Sep-04 9:06
nhoellei1-Sep-04 9:06 
GeneralRe: Determining if a file is locked by another process Pin
Heath Stewart1-Sep-04 15:47
protectorHeath Stewart1-Sep-04 15:47 
Use one of the larger overloads for the FileStream to request the access you want, as well as what access you want to share. If this is in conflict (you want write access but another process isn't sharing write access), an UnauthorizedAccessException will be thrown (this is documented for the FileStream class in the .NET Framework SDK).
If you want to continually try, you can use a simple loop but be careful. You might consider using a for loop with a set maximum number of tries before giving up, otherwise that thread of execution will block indefinitely:
FileStream file = null;
using (file)
{
  while (true)
  {
    try
    {
      file = new FileStream("file.lock", FileMode.OpenOrCreate, 
        FileAccess.Write, FileShare.Read);
      // Success! Use 'file'.
    }
    catch (UnauthorizedAccessException)
    {
    }
    catch (Exception e)
    {
      // Log 'e'.
      break;
    }
  }
}


This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralRe: Determining if a file is locked by another process Pin
Pradeep Shamarao2-Sep-04 21:00
Pradeep Shamarao2-Sep-04 21:00 
GeneralEvent handling in Custom Server Controls Pin
gorebash1-Sep-04 7:50
gorebash1-Sep-04 7:50 
GeneralRe: Event handling in Custom Server Controls Pin
Charlie Williams1-Sep-04 8:40
Charlie Williams1-Sep-04 8:40 
Generallocation based system Pin
mathon1-Sep-04 7:16
mathon1-Sep-04 7:16 
GeneralRe: location based system Pin
Heath Stewart1-Sep-04 15:33
protectorHeath Stewart1-Sep-04 15:33 
QuestionHow to cut a picture...?? Pin
Member 9401251-Sep-04 6:47
Member 9401251-Sep-04 6:47 
QuestionHow can I get width of window of my program when it change? Pin
arbrsoft1-Sep-04 5:51
arbrsoft1-Sep-04 5:51 
AnswerRe: How can I get width of window of my program when it change? Pin
LongRange.Shooter1-Sep-04 7:34
LongRange.Shooter1-Sep-04 7:34 
QuestionUnable to capture USB Gamepad using DirectInput? Pin
zhaonian1-Sep-04 4:57
zhaonian1-Sep-04 4:57 
AnswerRe: Unable to capture USB Gamepad using DirectInput? Pin
Heath Stewart1-Sep-04 15:27
protectorHeath Stewart1-Sep-04 15:27 
GeneralData Marshalling issues when Calling C++ dll in C# using P/Invoke Pin
KZHU011-Sep-04 4:17
KZHU011-Sep-04 4:17 
GeneralRe: Data Marshalling issues when Calling C++ dll in C# using P/Invoke Pin
Heath Stewart1-Sep-04 15:23
protectorHeath Stewart1-Sep-04 15:23 
GeneralNUnit - Specifying the order of Tests Pin
matthias s.1-Sep-04 3:44
matthias s.1-Sep-04 3:44 
GeneralRe: NUnit - Specifying the order of Tests Pin
Marc Clifton1-Sep-04 4:12
mvaMarc Clifton1-Sep-04 4:12 
GeneralRe: NUnit - Specifying the order of Tests Pin
Steven Campbell1-Sep-04 7:44
Steven Campbell1-Sep-04 7:44 
GeneralAxWebBrowser, BeforeNavigate2Event, postData problem Pin
Member 12847121-Sep-04 3:14
Member 12847121-Sep-04 3:14 
QuestionDrawing Window on Second Display...? Pin
jkersch1-Sep-04 1:14
jkersch1-Sep-04 1:14 

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.