正在被另一个进程使用 [英] Is being used by another process

查看:139
本文介绍了正在被另一个进程使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vb.net

我的应用程序有两个屏幕,第一个是主屏幕,第二个是客户屏幕

i需要显示第一个访问数据屏幕到第二个,所以为此我用file.copy将数据库复制到windows中的网络共享文件和file.copy再次将其接收回另一个。

问题是主要的屏幕(应用程序)说(文件正由另一个进程使用)



我只需要代码来检查文件是否被其他进程使用

使程序复制文件,当它没有被另一个进程使用时这是我的第二个屏幕





i搜索了很多,但我一无所获



我尝试过:



file.copy(source,path,true)

-------------------------------

解决方案

在单独的任务中执行文件复制,请参见此处的概述:任务类(System.Threading.Tasks)| Microsoft Docs [ ^ ]

这是一个简单的例子:VB任务控制示例 [ ^ ]

重要的部分是:

 Dim Tasks( 1)As Task 
Tasks(0)= Task.Factory.StartNew(Sub()TimedMatrixMultiplyCPU(1299))
Tasks(1)= Task.Factory.StartNew(Sub()TimedMatrixMultiplyGPU(1301))

''阻止所有任务完成
Task.WaitAll(任务)



如果可能,请阅读所有数据主应用程序中的内存,以便您始终可以访问内存中的数据,而无需使用文件访问。



更好的选择是使用像点ostgreSQL 或SQL Server,因为这些数据库可以轻松地同时访问,并且可以用于客户端 - 服务器方案。 https://www.slant.co/topics/5950/~relational-databases [ ^ ]


您可以使用Try ... Catch检查文件是否正在使用,请参见此处的示例: winforms - VB.NET在继续读/写之前检查文件是否打开? - 堆栈溢出 [ ^ ]



另一个想法可能是将客户的数据导出为CSV并让服务器应用程序导入它,请参见此处的示例:通过VB.net 2010快速将csv文件导入访问数据库 - Stack Overflow [ ^ ]

这样你可以避免文件锁定问题。 / BLOCKQUOTE>

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)
-------------------------------

解决方案

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[^]


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.


这篇关于正在被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆