473,686 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Process cannot access file" problem

Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileS ystemEventArgs)
If e.ChangeType = WatcherChangeTy pes.Created Then
System.IO.File. Move(e.FullPath , textBoxDest.Tex t & "\" & e.Name)
End If
e.FullPath returns the full path and filename of the file created e.g
c:\filename.txt
textboxDest is where the file is to be moved to e.g D:\
e.Name is the filename without the path e.g. filename.txt

This is the error text...

System.IO.IOExc eption: The process cannot access the file
"D:\Unsorted\20 05\New.mp3" because it is being used by another process.
What happens is files get downloaded to the D:\Unsorted\ folder which is
being monitored by the FileSystemWatch er. The app then tries to move the
downloaded/created file to the D:\Unsorted\200 5\ folder then the error
occurs.

Any help much appreciated,
Thanks
Paul
Nov 21 '05 #1
10 15876
I had simular problems with my filewatch program. It happend when I had a
window open on that directory in thumbnail or filmstrip mode. I also got a
tip about check if the file is finished before move it. try opend the file.
I have not tested the tip yet.

Petter L

"Paul" <pr*****@mail.c om> wrote in message
news:41******** *************** @mercury.nildra m.net...
Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileS ystemEventArgs)
If e.ChangeType = WatcherChangeTy pes.Created Then
System.IO.File. Move(e.FullPath , textBoxDest.Tex t & "\" & e.Name)
End If
e.FullPath returns the full path and filename of the file created e.g
c:\filename.txt
textboxDest is where the file is to be moved to e.g D:\
e.Name is the filename without the path e.g. filename.txt

This is the error text...

System.IO.IOExc eption: The process cannot access the file
"D:\Unsorted\20 05\New.mp3" because it is being used by another process.
What happens is files get downloaded to the D:\Unsorted\ folder which is
being monitored by the FileSystemWatch er. The app then tries to move the
downloaded/created file to the D:\Unsorted\200 5\ folder then the error
occurs.

Any help much appreciated,
Thanks
Paul

Nov 21 '05 #2
Hi again

Right after my first nessage I got the problem again in my program. When I
halted right before the copy action and steped though it, it worked most of
the times but if i let the program run it created a "Process cannot access
file" and it pointed to the destination path for the file. What i did was to
put

System.Threadin g.Thread.Sleep( 5000)

before the copy routine and now it works fine.

Maybe this can help on your problem too ?

Petter L.

"Paul" <pr*****@mail.c om> wrote in message
news:41******** *************** @mercury.nildra m.net...
Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileS ystemEventArgs)
If e.ChangeType = WatcherChangeTy pes.Created Then
System.IO.File. Move(e.FullPath , textBoxDest.Tex t & "\" & e.Name)
End If
e.FullPath returns the full path and filename of the file created e.g
c:\filename.txt
textboxDest is where the file is to be moved to e.g D:\
e.Name is the filename without the path e.g. filename.txt

This is the error text...

System.IO.IOExc eption: The process cannot access the file
"D:\Unsorted\20 05\New.mp3" because it is being used by another process.
What happens is files get downloaded to the D:\Unsorted\ folder which is
being monitored by the FileSystemWatch er. The app then tries to move the
downloaded/created file to the D:\Unsorted\200 5\ folder then the error
occurs.

Any help much appreciated,
Thanks
Paul

Nov 21 '05 #3
Thanks for the tip Petter. It works on my problem too but I would prefer to
use a better way if one is known.

Is it possible to lock the file being moved so that no other process can
access the file? E.g. Windows trying to extract thumbnail, ID3 tag etc.

Thanks,
Paul

"petterl" <pe**********@h otmail.com> wrote in message
news:u2******** ******@TK2MSFTN GP12.phx.gbl...
Hi again

Right after my first nessage I got the problem again in my program. When I
halted right before the copy action and steped though it, it worked most
of the times but if i let the program run it created a "Process cannot
access file" and it pointed to the destination path for the file. What i
did was to put

System.Threadin g.Thread.Sleep( 5000)

before the copy routine and now it works fine.

Maybe this can help on your problem too ?

Petter L.

"Paul" <pr*****@mail.c om> wrote in message
news:41******** *************** @mercury.nildra m.net...
Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileS ystemEventArgs)
If e.ChangeType = WatcherChangeTy pes.Created Then
System.IO.File. Move(e.FullPath , textBoxDest.Tex t & "\" & e.Name)
End If
e.FullPath returns the full path and filename of the file created e.g
c:\filename.txt
textboxDest is where the file is to be moved to e.g D:\
e.Name is the filename without the path e.g. filename.txt

This is the error text...

System.IO.IOExc eption: The process cannot access the file
"D:\Unsorted\20 05\New.mp3" because it is being used by another process.
What happens is files get downloaded to the D:\Unsorted\ folder which is
being monitored by the FileSystemWatch er. The app then tries to move the
downloaded/created file to the D:\Unsorted\200 5\ folder then the error
occurs.

Any help much appreciated,
Thanks
Paul


Nov 21 '05 #4
Hello,

I'm not sure if you are running into the same issue I had a while back or
not, but just incase here are my thoughts.

I remember I would get the same error and the only way I could get around it
was by calling dispose on the FileSystemWatch er. Here are my notes from the
code I wrote a while back
/// Release handles to directory. A directory cannot be fully
/// deleted until it is released. Need to use Dispose because
/// can't wait for garbage collector.

It worked for me. So I my architectured was a class called
FileSystemMonit er (which I created) and in this class I setup the
FileSystemWatch er and exposed the events of FileSystemWatch er. Mine might
be a bit different in that for each FileSystemWatch er event I had them raise
a my own Changed event so that my subscribers only had to listen to one
event when any changes occured.

Then when I needed to start and stop watching I released the references to
the changed event and called dispose on the FileSystemMonit or. Here is some
of the code.
/// <summary>

/// Monitors the file system for any changes in the specified path.

/// </summary>

public class FileSystemMonit or : IDisposable {
# region ***** FIELDS *****

private int _ignoreChangesP eriod;

private int _lastChangeTime ;

private FileSystemWatch er _watcher;

private FileSystemWatch er _watcherChanged ;

private string _watchPath;

public delegate void FileSystemChang edHandler(objec t sender,
FileSystemEvent Args e);

public event FileSystemChang edHandler Changed;

# endregion

# region ***** CONSTRUCTORS *****

public FileSystemMonit or(string path) {

_watchPath = path;

_watcher = new FileSystemWatch er();

_watcher.Create d += new FileSystemEvent Handler(OnFileC reated);

_watcher.Delete d += new FileSystemEvent Handler(OnFileD eleted);

_watcher.Rename d += new RenamedEventHan dler(OnFileRena med); // NOTE: THIS
MAY NOT BE WORKING.

SetWatcherPrope rties(_watcher) ;

// Setup second watcher to watch changed because

// Create, Delete, and rename don't seem to fire when NotifyFilter is set.

// NOTE: THIS MAY NOT BE WORKING.

_watcherChanged = new FileSystemWatch er();

_watcherChanged .Changed += new FileSystemEvent Handler(OnFileC hanged);

_watcherChanged .NotifyFilter = NotifyFilters.F ileName |
NotifyFilters.D irectoryName;

SetWatcherPrope rties(_watcherC hanged);

}

# endregion

# region ***** PUBLIC METHODS *****

/// <summary>

/// Release handles to directory. A directory cannot be fully

/// deleted until it is released. Need to use Dispose because

/// can't wait for garbage collector.

/// </summary>

public void Dispose() {

_watcher.Dispos e();

_watcherChanged .Dispose();

}

# endregion

# region ***** PRIVATE METHODS *****

private void SetWatcherPrope rties(FileSyste mWatcher watcher) {

watcher.Path = _watchPath;

watcher.Filter = "*.*";

watcher.Include Subdirectories = true;

watcher.EnableR aisingEvents = true;

}

private void OnFileCreated(o bject sender, FileSystemEvent Args e) {

Debug.WriteLine ("FileSystmeMon itor.OnFileCrea ted: " + e.FullPath);

CallChanged(sen der, e);

}

private void OnFileDeleted(o bject sender, FileSystemEvent Args e) {

Debug.WriteLine ("FileSystmeMon itor.OnFileDele ted: " + e.FullPath);

CallChanged(sen der, e);

}

private void OnFileRenamed(o bject sender, RenamedEventArg s e) {

Debug.WriteLine ("FileSystmeMon itor.OnFileRena med: " + e.FullPath);

CallChanged(sen der, e);

}

private void OnFileChanged(o bject sender, FileSystemEvent Args e) {

Debug.WriteLine ("FileSystmeMon itor.OnFileChan ged: " + e.FullPath);

CallChanged(sen der, e);

}

private void CallChanged(obj ect sender, FileSystemEvent Args e) {
// Check if should ignore change.

int currentTime = System.Environm ent.TickCount;

if (currentTime - _lastChangeTime > _ignoreChangesP eriod) {

if (this.Changed != null) {

this.Changed(se nder, e);

}

} else {

Debug.WriteLine ("CallChange d Ignored");

}

_lastChangeTime = currentTime;

}

# endregion

#region ***** PROPERTIES *****

public int IgnoreChangesMi liseconds {

get { return _ignoreChangesP eriod; }

set { _ignoreChangesP eriod = value; }

}

#endregion

}

-----

These methods were in another class that was using The FileSystemMonit or.

public void StartFileMonito r() {
Debug.WriteLine ("Start File Monitor: " + this.Directory) ;

// Setup file system monitor. This object will alert

// this image to reload when changes occur to the file system.

if (_fileSystemMon itor == null) {

_fileSystemMoni tor = new FileSystemMonit or(_dirPath);

_fileSystemMoni tor.IgnoreChang esMiliseconds =
AppManager.FILE _SYSTEM_IGNORE_ CHANGES_TIME;

}

if (_fileSystemCha ngedHandler == null) {

_fileSystemChan gedHandler = new
FileSystemMonit or.FileSystemCh angedHandler(Fi leSystemMonitor _OnFileSystemCh anged);

Debug.WriteLine ("FileSystemHan dler Created: " + this.Directory) ;

}
_fileSystemMoni tor.Changed += _fileSystemChan gedHandler;

Debug.WriteLine ("FileSystemHan dler Added: " + this.Directory) ;

}

public void StopFileMonitor () {

Debug.WriteLine ("Stoping File Monitor: " + this.Directory) ;

// Remove event handler;

if (_fileSystemCha ngedHandler != null) {

_fileSystemMoni tor.Changed -= _fileSystemChan gedHandler;

Debug.WriteLine ("FileSystemCha ngedHandler Removed: " + this.Directory) ;
}

if (_fileSystemMon itor != null) {

_fileSystemMoni tor.Dispose();

Debug.WriteLine ("FileSystemMon itor Disposed");

//_fileSystemMoni tor = null;

}

}

Hope that helps.


--
Tom Krueger

Smart Client DevCenter - http://msdn.microsoft.com/smartclient/
Mobile DevCenter - http://msdn.microsoft.com/mobility

This posting is provided "as is" with no warranties and confers no rights.

"Paul" <pr*****@mail.c om> wrote in message
news:41******** *************** @mercury.nildra m.net...
Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileS ystemEventArgs)
If e.ChangeType = WatcherChangeTy pes.Created Then
System.IO.File. Move(e.FullPath , textBoxDest.Tex t & "\" & e.Name)
End If
e.FullPath returns the full path and filename of the file created e.g
c:\filename.txt
textboxDest is where the file is to be moved to e.g D:\
e.Name is the filename without the path e.g. filename.txt

This is the error text...

System.IO.IOExc eption: The process cannot access the file
"D:\Unsorted\20 05\New.mp3" because it is being used by another process.
What happens is files get downloaded to the D:\Unsorted\ folder which is
being monitored by the FileSystemWatch er. The app then tries to move the
downloaded/created file to the D:\Unsorted\200 5\ folder then the error
occurs.

Any help much appreciated,
Thanks
Paul

Nov 21 '05 #5
I found out it whas not a perfect solution but it worked on small files but
big files it came back. So I looking into the other tip here also

Petter L.
"Paul" <pr*****@mail.c om> wrote in message
news:41******** *************@m ercury.nildram. net...
Thanks for the tip Petter. It works on my problem too but I would prefer
to use a better way if one is known.

Is it possible to lock the file being moved so that no other process can
access the file? E.g. Windows trying to extract thumbnail, ID3 tag etc.

Thanks,
Paul

"petterl" <pe**********@h otmail.com> wrote in message
news:u2******** ******@TK2MSFTN GP12.phx.gbl...
Hi again

Right after my first nessage I got the problem again in my program. When
I halted right before the copy action and steped though it, it worked
most of the times but if i let the program run it created a "Process
cannot access file" and it pointed to the destination path for the file.
What i did was to put

System.Threadin g.Thread.Sleep( 5000)

before the copy routine and now it works fine.

Maybe this can help on your problem too ?

Petter L.

"Paul" <pr*****@mail.c om> wrote in message
news:41******** *************** @mercury.nildra m.net...
Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileS ystemEventArgs)
If e.ChangeType = WatcherChangeTy pes.Created Then
System.IO.File. Move(e.FullPath , textBoxDest.Tex t & "\" & e.Name)
End If
e.FullPath returns the full path and filename of the file created e.g
c:\filename.txt
textboxDest is where the file is to be moved to e.g D:\
e.Name is the filename without the path e.g. filename.txt

This is the error text...

System.IO.IOExc eption: The process cannot access the file
"D:\Unsorted\20 05\New.mp3" because it is being used by another process.
What happens is files get downloaded to the D:\Unsorted\ folder which is
being monitored by the FileSystemWatch er. The app then tries to move
the downloaded/created file to the D:\Unsorted\200 5\ folder then the
error occurs.

Any help much appreciated,
Thanks
Paul



Nov 21 '05 #6
I found out it whas not a perfect solution but it worked on small files but
big files it came back. So I looking into the other tip here also

Petter L.
"Paul" <pr*****@mail.c om> wrote in message
news:41******** *************@m ercury.nildram. net...
Thanks for the tip Petter. It works on my problem too but I would prefer
to use a better way if one is known.

Is it possible to lock the file being moved so that no other process can
access the file? E.g. Windows trying to extract thumbnail, ID3 tag etc.

Thanks,
Paul

"petterl" <pe**********@h otmail.com> wrote in message
news:u2******** ******@TK2MSFTN GP12.phx.gbl...
Hi again

Right after my first nessage I got the problem again in my program. When
I halted right before the copy action and steped though it, it worked
most of the times but if i let the program run it created a "Process
cannot access file" and it pointed to the destination path for the file.
What i did was to put

System.Threadin g.Thread.Sleep( 5000)

before the copy routine and now it works fine.

Maybe this can help on your problem too ?

Petter L.

"Paul" <pr*****@mail.c om> wrote in message
news:41******** *************** @mercury.nildra m.net...
Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileS ystemEventArgs)
If e.ChangeType = WatcherChangeTy pes.Created Then
System.IO.File. Move(e.FullPath , textBoxDest.Tex t & "\" & e.Name)
End If
e.FullPath returns the full path and filename of the file created e.g
c:\filename.txt
textboxDest is where the file is to be moved to e.g D:\
e.Name is the filename without the path e.g. filename.txt

This is the error text...

System.IO.IOExc eption: The process cannot access the file
"D:\Unsorted\20 05\New.mp3" because it is being used by another process.
What happens is files get downloaded to the D:\Unsorted\ folder which is
being monitored by the FileSystemWatch er. The app then tries to move
the downloaded/created file to the D:\Unsorted\200 5\ folder then the
error occurs.

Any help much appreciated,
Thanks
Paul



Nov 21 '05 #7
Petter L wrote:
I found out it whas not a perfect solution but it worked on small files but
big files it came back. So I looking into the other tip here also


Hi Petter.

I've had the same problem. My solution was something like this:

/// <summary>
/// This method returns as soon as the specified file is writeable.
/// </summary>
/// <param name="fileName" >The full path to the file.</param>
protected void waitForFile(str ing fileName) {
new FileWaiter(file Name).DoWait();
}

[...]
internal class FileWaiter {
public string fileName;

public FileWaiter(stri ng fileName) {
this.fileName = fileName;
}

public void DoWait(int timeout) {
DoWait(new TimeSpan(0, 0, 0, 0, timeout));
}

public void DoWait() {
DoWait(TimeSpan .MinValue);
}

public void DoWait(TimeSpan timeout) {
System.Diagnost ics.Debug.Asser t(filename != null);
Thread t = new Thread(new ThreadStart(Thr eadWait));
t.Start();
if (timeout > TimeSpan.MinVal ue)
t.Join(timeout) ;
else
t.Join();
}

void ThreadWait() {
do {
//Start waiting..
Thread.Sleep(50 0);
}
while (System.IO.File .Exists(fileNam e) && isFileOpen(file Name));
}
}

protected static bool isFileOpen(stri ng fileName) {
System.IO.FileS tream s = null;
try {
s = System.IO.File. Open(fileName, System.IO.FileM ode.Open,
System.IO.FileA ccess.ReadWrite ,
System.IO.FileS hare.None);
return false;
} catch (System.IO.IOEx ception) {
return true;
} finally {
if (s != null)
s.Close();
}
}
[...]
Nov 21 '05 #8
Petter L wrote:
I found out it whas not a perfect solution but it worked on small files but
big files it came back. So I looking into the other tip here also


Hi Petter.

I've had the same problem. My solution was something like this:

/// <summary>
/// This method returns as soon as the specified file is writeable.
/// </summary>
/// <param name="fileName" >The full path to the file.</param>
protected void waitForFile(str ing fileName) {
new FileWaiter(file Name).DoWait();
}

[...]
internal class FileWaiter {
public string fileName;

public FileWaiter(stri ng fileName) {
this.fileName = fileName;
}

public void DoWait(int timeout) {
DoWait(new TimeSpan(0, 0, 0, 0, timeout));
}

public void DoWait() {
DoWait(TimeSpan .MinValue);
}

public void DoWait(TimeSpan timeout) {
System.Diagnost ics.Debug.Asser t(filename != null);
Thread t = new Thread(new ThreadStart(Thr eadWait));
t.Start();
if (timeout > TimeSpan.MinVal ue)
t.Join(timeout) ;
else
t.Join();
}

void ThreadWait() {
do {
//Start waiting..
Thread.Sleep(50 0);
}
while (System.IO.File .Exists(fileNam e) && isFileOpen(file Name));
}
}

protected static bool isFileOpen(stri ng fileName) {
System.IO.FileS tream s = null;
try {
s = System.IO.File. Open(fileName, System.IO.FileM ode.Open,
System.IO.FileA ccess.ReadWrite ,
System.IO.FileS hare.None);
return false;
} catch (System.IO.IOEx ception) {
return true;
} finally {
if (s != null)
s.Close();
}
}
[...]
Nov 21 '05 #9
I appreciate the code guys and the time spent replying but I'm afraid I
don't have a clue on how introduce any of it into my project as the two
examples posted have been in C as opposed to VB. I just realised I posted
this in the the dotnet.general NG aswell as the donet.languages .vb NG which
I suppose is why I got replies in C!
Sorry for the mistake. I guess I'll keep on looking!

Cheers,
Paul

"Tom Krueger [MSFT]" <a-******@online.m icrosoft.com> wrote in message
news:uV******** ******@TK2MSFTN GP15.phx.gbl...
Hello,

I'm not sure if you are running into the same issue I had a while back or
not, but just incase here are my thoughts.

I remember I would get the same error and the only way I could get around
it was by calling dispose on the FileSystemWatch er. Here are my notes
from the code I wrote a while back
/// Release handles to directory. A directory cannot be fully
/// deleted until it is released. Need to use Dispose because
/// can't wait for garbage collector.

It worked for me. So I my architectured was a class called
FileSystemMonit er (which I created) and in this class I setup the
FileSystemWatch er and exposed the events of FileSystemWatch er. Mine might
be a bit different in that for each FileSystemWatch er event I had them
raise a my own Changed event so that my subscribers only had to listen to
one event when any changes occured.

Then when I needed to start and stop watching I released the references to
the changed event and called dispose on the FileSystemMonit or. Here is
some of the code.
/// <summary>

/// Monitors the file system for any changes in the specified path.

/// </summary>

public class FileSystemMonit or : IDisposable {
# region ***** FIELDS *****

private int _ignoreChangesP eriod;

private int _lastChangeTime ;

private FileSystemWatch er _watcher;

private FileSystemWatch er _watcherChanged ;

private string _watchPath;

public delegate void FileSystemChang edHandler(objec t sender,
FileSystemEvent Args e);

public event FileSystemChang edHandler Changed;

# endregion

# region ***** CONSTRUCTORS *****

public FileSystemMonit or(string path) {

_watchPath = path;

_watcher = new FileSystemWatch er();

_watcher.Create d += new FileSystemEvent Handler(OnFileC reated);

_watcher.Delete d += new FileSystemEvent Handler(OnFileD eleted);

_watcher.Rename d += new RenamedEventHan dler(OnFileRena med); // NOTE: THIS
MAY NOT BE WORKING.

SetWatcherPrope rties(_watcher) ;

// Setup second watcher to watch changed because

// Create, Delete, and rename don't seem to fire when NotifyFilter is set.

// NOTE: THIS MAY NOT BE WORKING.

_watcherChanged = new FileSystemWatch er();

_watcherChanged .Changed += new FileSystemEvent Handler(OnFileC hanged);

_watcherChanged .NotifyFilter = NotifyFilters.F ileName |
NotifyFilters.D irectoryName;

SetWatcherPrope rties(_watcherC hanged);

}

# endregion

# region ***** PUBLIC METHODS *****

/// <summary>

/// Release handles to directory. A directory cannot be fully

/// deleted until it is released. Need to use Dispose because

/// can't wait for garbage collector.

/// </summary>

public void Dispose() {

_watcher.Dispos e();

_watcherChanged .Dispose();

}

# endregion

# region ***** PRIVATE METHODS *****

private void SetWatcherPrope rties(FileSyste mWatcher watcher) {

watcher.Path = _watchPath;

watcher.Filter = "*.*";

watcher.Include Subdirectories = true;

watcher.EnableR aisingEvents = true;

}

private void OnFileCreated(o bject sender, FileSystemEvent Args e) {

Debug.WriteLine ("FileSystmeMon itor.OnFileCrea ted: " + e.FullPath);

CallChanged(sen der, e);

}

private void OnFileDeleted(o bject sender, FileSystemEvent Args e) {

Debug.WriteLine ("FileSystmeMon itor.OnFileDele ted: " + e.FullPath);

CallChanged(sen der, e);

}

private void OnFileRenamed(o bject sender, RenamedEventArg s e) {

Debug.WriteLine ("FileSystmeMon itor.OnFileRena med: " + e.FullPath);

CallChanged(sen der, e);

}

private void OnFileChanged(o bject sender, FileSystemEvent Args e) {

Debug.WriteLine ("FileSystmeMon itor.OnFileChan ged: " + e.FullPath);

CallChanged(sen der, e);

}

private void CallChanged(obj ect sender, FileSystemEvent Args e) {
// Check if should ignore change.

int currentTime = System.Environm ent.TickCount;

if (currentTime - _lastChangeTime > _ignoreChangesP eriod) {

if (this.Changed != null) {

this.Changed(se nder, e);

}

} else {

Debug.WriteLine ("CallChange d Ignored");

}

_lastChangeTime = currentTime;

}

# endregion

#region ***** PROPERTIES *****

public int IgnoreChangesMi liseconds {

get { return _ignoreChangesP eriod; }

set { _ignoreChangesP eriod = value; }

}

#endregion

}

-----

These methods were in another class that was using The FileSystemMonit or.

public void StartFileMonito r() {
Debug.WriteLine ("Start File Monitor: " + this.Directory) ;

// Setup file system monitor. This object will alert

// this image to reload when changes occur to the file system.

if (_fileSystemMon itor == null) {

_fileSystemMoni tor = new FileSystemMonit or(_dirPath);

_fileSystemMoni tor.IgnoreChang esMiliseconds =
AppManager.FILE _SYSTEM_IGNORE_ CHANGES_TIME;

}

if (_fileSystemCha ngedHandler == null) {

_fileSystemChan gedHandler = new
FileSystemMonit or.FileSystemCh angedHandler(Fi leSystemMonitor _OnFileSystemCh anged);

Debug.WriteLine ("FileSystemHan dler Created: " + this.Directory) ;

}
_fileSystemMoni tor.Changed += _fileSystemChan gedHandler;

Debug.WriteLine ("FileSystemHan dler Added: " + this.Directory) ;

}

public void StopFileMonitor () {

Debug.WriteLine ("Stoping File Monitor: " + this.Directory) ;

// Remove event handler;

if (_fileSystemCha ngedHandler != null) {

_fileSystemMoni tor.Changed -= _fileSystemChan gedHandler;

Debug.WriteLine ("FileSystemCha ngedHandler Removed: " + this.Directory) ;
}

if (_fileSystemMon itor != null) {

_fileSystemMoni tor.Dispose();

Debug.WriteLine ("FileSystemMon itor Disposed");

//_fileSystemMoni tor = null;

}

}

Hope that helps.


--
Tom Krueger

Smart Client DevCenter - http://msdn.microsoft.com/smartclient/
Mobile DevCenter - http://msdn.microsoft.com/mobility

This posting is provided "as is" with no warranties and confers no rights.

"Paul" <pr*****@mail.c om> wrote in message
news:41******** *************** @mercury.nildra m.net...
Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileS ystemEventArgs)
If e.ChangeType = WatcherChangeTy pes.Created Then
System.IO.File. Move(e.FullPath , textBoxDest.Tex t & "\" & e.Name)
End If
e.FullPath returns the full path and filename of the file created e.g
c:\filename.txt
textboxDest is where the file is to be moved to e.g D:\
e.Name is the filename without the path e.g. filename.txt

This is the error text...

System.IO.IOExc eption: The process cannot access the file
"D:\Unsorted\20 05\New.mp3" because it is being used by another process.
What happens is files get downloaded to the D:\Unsorted\ folder which is
being monitored by the FileSystemWatch er. The app then tries to move the
downloaded/created file to the D:\Unsorted\200 5\ folder then the error
occurs.

Any help much appreciated,
Thanks
Paul


Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
715
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
2
2845
by: Henrik | last post by:
Hi Im trying to make an app that uses threading, I want to write to a file in a loop. How can i ensure that only one thread writes to the file a the time??? Im accessing the fil with: Dim xFile As StreamWriter
2
2906
by: lucy | last post by:
Hi, I use ADOX to create a Access database programmatically from my asp.net application and save ".mdb" file to a temp folder under my project foler on the web server. After database is created successfuly, I saw two files ".mdb" and ".ldb" in my temp folder. I have no problem to open the database manually. But when I'm tring to use Response.WriteFile() to download database file to end user's local machine, I kept getting the following
7
23177
by: RSH | last post by:
Hi, I have an ASP .Net web page that creates a temp directory on the server then it is using the File.Copy command to move a file to a temp download directory, Then I am doing a response.Redirect to that URL. The problem is that whenever I run the page the script fails on the File.Copy() command everytime with an error of: The process cannot access the file
0
8516
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8932
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7599
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4308
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1934
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.