如何基于文件名获取进程名称 [英] How to get Process name on the basis of File Name

查看:213
本文介绍了如何基于文件名获取进程名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.....

我需要帮助,我想知道正在使用文件的进程名称.

前任.我想知道文件ABC.txt是由哪个进程打开的.


其实我想要这个是因为我正在执行连续打印,我正在执行的步骤是

STEP1:检查Rich1.txt是否存在,那么我首先将其删除,然后使用名称Rich1.txt创建新的txt

第2步:现在,使用streamwriter编写字符.写完角色后,我将关闭Closing Streamwriter

第3步编写Rich1.txt之后,将其发送到RawPrinter(Printer)


但是真正的问题是,当我连续打印(一个接一个)时
然后是第一次打印,但是第二次是
那么在 step1 处抛出异常,表明 C:\ Rich1.txt被另一个进程使用

我无法知道哪个进程正在使用它.我在Taskmanager中查找了notepad.exe(,因为.txt是由记事本打开的),但我没有.

欢迎任何帮助.....!

Hi Guys.....

I need help , I want to know Process Name which is using a file.

Ex. I want to know file ABC.txt is opened by which Process.


Actually i want this because, I am doing Continuous Printing , the steps I am doing is following

STEP1 : Checking If Rich1.txt Exist or not if Yes, then I am deleting it first , then Creating new txt with Name Rich1.txt

Step 2: Now writing characters using streamwriter. After writing Characters i am closing Closing streamwriter

Step3 After writing Rich1.txt Sending it to RawPrinter(Printer)


But the Real Problem is that when i Do continuous Printing (One after One)
then first time it is Printing ok , But when it comes for second time
then it is throwing exception at step1 that C:\Rich1.txt is used by another Process

I am unable to konow which process is using it . I look in Taskmanager for notepad.exe ( because .txt is opened by notepad ) but i not got.

Any Help is Welcome.....!

推荐答案

您自己的应用程序有可能正在使用它.
首先要做的是对应用程序中的所有流使用Dispose-关闭可能不足.
其次,如果不能解决问题,那么很有可能RawPrinter会打开文件,直到完全完成打印输出为止.

尝试以下操作:从代码中删除RawPrinter内容以进行测试-问题仍然存在吗?如果不是,则您知道问题出在哪里-您将不得不等待直到打印完成为止.
The chances are it is in use by your own application.
First thing to do is to use Dispose on any and all streams in your app - Close may not be sufficient.
Secondly, if that doesn''t fix it, then there is a very good chance that the RawPrinter has the file open until it is completely finished with the print out.

Try this: Remove the RawPrinter stuff from your code for testing - does the problem still persists? If it doesn''t, then you know where the problem is - you will have to wait until the print is complete somehow.


什么是vb .net.为什么要使用vb.net./pre>>
what is vb.net .why do we use of vb.net./pre>>


我通过使用两个textDocument 例如Rich1.txt,Rich2.txt和

当我检查文件 Rich1.txt 是否存在时?在这里,它给出了例外.我将这段代码放在尝试Catch中,当Control转到Catch Line时,我开始编写 Rich2.txt
并将其发送到打印机.
I solve it Problem by using two textDocument For Ex. Rich1.txt and Rich2.txt and

When i checked for File Rich1.txt if it exist ? here, it is giving exception . I put this code in try Catch and when Control goes to Catch Line then I start writing Rich2.txt
and Send it to Printer.


这篇关于如何基于文件名获取进程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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