Click here to Skip to main content
15,901,122 members
Home / Discussions / C#
   

C#

 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 12:41
Aviv Halperin22-Dec-04 12:41 
GeneralRe: TextBox Pin
Heath Stewart22-Dec-04 12:43
protectorHeath Stewart22-Dec-04 12:43 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 12:49
Aviv Halperin22-Dec-04 12:49 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 12:51
Aviv Halperin22-Dec-04 12:51 
GeneralRe: TextBox Pin
Skynyrd22-Dec-04 12:56
Skynyrd22-Dec-04 12:56 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 13:04
Aviv Halperin22-Dec-04 13:04 
GeneralFile.Copy question Pin
Marius Schumann22-Dec-04 9:39
Marius Schumann22-Dec-04 9:39 
GeneralRe: File.Copy question Pin
Heath Stewart22-Dec-04 12:06
protectorHeath Stewart22-Dec-04 12:06 
You need to synchronize your methods. When the timer elapses the method is executed in a separate thread that executes asynchronously with the rest of your application. Do get around this there's many classes in the System.Threading namespace you should read about, like a Mutex or a Monitor. C# also defines the lock keyword to lock against a static object (so your copy and modification code should lock against the same object), which compiles down to a Monitor.

The not-so-obvious gotcha is that you should allow queues for the locked object to timeout. If a file copy operation takes 30 minutes for some reason, you could have a couple of requests for the locked object in order to modify the file. Now, maybe this is desirable (to make sure the changes get in there, but to ensure that those changes are updated you really should look into better serialization approaches in case your app dies for some unexpected reason).

Here's an example:
static object sync = new object();
 
private void Copy()
{
  lock (sync)
  {
    // Copy the file.
  }
}
 
private void Modify()
{
  lock (sync)
  {
    // Modify the file.
  }
}
Again, if you want more control over how your code is synchronized then take a look at the other classes in the System.Threading namespace in the .NET Framework SDK, which is installed by default with VS.NET and is available online at http://msdn.microsoft.com/library[^].

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

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: File.Copy question Pin
Salil Khedkar22-Dec-04 19:32
Salil Khedkar22-Dec-04 19:32 
GeneraltextBox vs. richtextBox and savefiledialog controls Pin
Pyro Joe22-Dec-04 8:42
Pyro Joe22-Dec-04 8:42 
GeneralRe: textBox vs. richtextBox and savefiledialog controls Pin
Dave Kreskowiak22-Dec-04 9:53
mveDave Kreskowiak22-Dec-04 9:53 
Generalgetting html stored in xml using XmlTextReader() Pin
HudsonKane22-Dec-04 8:23
HudsonKane22-Dec-04 8:23 
GeneralPassing data from ASPX to ASCX Pin
Tony Nero22-Dec-04 8:22
Tony Nero22-Dec-04 8:22 
GeneralRe: Passing data from ASPX to ASCX Pin
Heath Stewart22-Dec-04 11:52
protectorHeath Stewart22-Dec-04 11:52 
Generalupdate dataadapter fails on duplicate identity column key Pin
JeromeKJerome22-Dec-04 6:51
JeromeKJerome22-Dec-04 6:51 
GeneralRe: update dataadapter fails on duplicate identity column key Pin
Heath Stewart22-Dec-04 11:55
protectorHeath Stewart22-Dec-04 11:55 
GeneralRe: update dataadapter fails on duplicate identity column key Pin
JeromeKJerome25-Dec-04 15:20
JeromeKJerome25-Dec-04 15:20 
GeneralRe: update dataadapter fails on duplicate identity column key Pin
Heath Stewart27-Dec-04 10:25
protectorHeath Stewart27-Dec-04 10:25 
GeneralTreeView and Context Menu Pin
MarkMokris22-Dec-04 5:12
MarkMokris22-Dec-04 5:12 
GeneralRe: TreeView and Context Menu Pin
Guinness4Strength22-Dec-04 5:25
Guinness4Strength22-Dec-04 5:25 
GeneralRe: TreeView and Context Menu Pin
MarkMokris22-Dec-04 5:42
MarkMokris22-Dec-04 5:42 
Generalregistry policy settings refresh Pin
Pyro Joe22-Dec-04 4:54
Pyro Joe22-Dec-04 4:54 
GeneralRe: registry policy settings refresh Pin
Guinness4Strength22-Dec-04 5:21
Guinness4Strength22-Dec-04 5:21 
GeneralRe: registry policy settings refresh Pin
Pyro Joe22-Dec-04 5:40
Pyro Joe22-Dec-04 5:40 
GeneralRe: registry policy settings refresh Pin
Dave Kreskowiak22-Dec-04 6:39
mveDave Kreskowiak22-Dec-04 6:39 

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.