Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i'm using vb.net
my application has two screen the first is main screen and the second is customer screen
i need to show access data from the first screen to the second one, so for that i used file.copy to copy database to network share file in windows and file.copy again to receive it back on the other.
the problem is that the main screen (application) says ("file is being used by another process)

what i need just code to check if file is being used by another process or not
to make the program copy files when it's not used by another process "which is my second screen"


i searched a lot but i found nothing

What I have tried:

file.copy(source,path,true)
-------------------------------
Posted
Updated 28-May-19 9:31am
v2
Comments
Dave Kreskowiak 28-May-19 15:14pm    
Let me get this straight. You're copying an Access database file so you can show data in your second form? ... and these two forms are in the same project?
RickZeeland 28-May-19 15:28pm    
He probably means a Client-Server like application with a main server application and a client that a customer can use.
Dave Kreskowiak 28-May-19 16:05pm    
I try to assume nothing, and his post starts with "my application", no "s" on the end.
RickZeeland 29-May-19 1:57am    
We'll see if the OP will shine some light on this, but it would be very strange if he uses only one application on one PC !
Dave Kreskowiak 29-May-19 8:40am    
I doubt we'll see. The OP doesn't have a history of responding to questions.

Do the file copy in a separate Task, see overview here: Task Class (System.Threading.Tasks) | Microsoft Docs[^]
Here is a simple example: VB Task Control Example[^]
The important part is:
Dim Tasks(1) As Task
Tasks(0) = Task.Factory.StartNew(Sub() TimedMatrixMultiplyCPU(1299))
Tasks(1) = Task.Factory.StartNew(Sub() TimedMatrixMultiplyGPU(1301))

'' Block until all tasks complete
Task.WaitAll(Tasks)

If possible read all data in memory in the main application so that you can always access the data in memory without having to use file access.

A better option would be to use a database like PostgreSQL or SQL Server as these databases can handle simultaneous access easily and are made for Client-Server scenario's. https://www.slant.co/topics/5950/~relational-databases[^]
 
Share this answer
 
v5
Comments
Member 11903597 28-May-19 14:33pm    
i didn't understand the microsoft article
:/
can you write a simple example
You can use Try ... Catch to check if a file is in use, see example here: winforms - VB.NET Checking if a File is Open before proceeding with a Read/Write? - Stack Overflow[^]

Another idea might be to export the Client's data to CSV and let the Server application import it, see example here: Fast import of csv file into access database via VB.net 2010 - Stack Overflow[^]
This way you can avoid file locking problems.
 
Share this answer
 
v2
Comments
Member 11903597 29-May-19 11:29am    
you are amazing thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900