计时器时间表或间隔 [英] Timer schedule or interval

查看:82
本文介绍了计时器时间表或间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看更多:C#

我试图每隔15秒安排一次图像捕捉;我有一个两个门的字符串数组。我试图在图像捕获上设置间隔,但我没有得到结果我得到的关闭是用当前时间戳保存的图像;当代码在间隔15秒之后通过第二组图像时,新图像采用第一组图像的时间戳,从而用相同的时间戳替换原始图像但是拍摄当前图像。



我需要按照图像创建的当前时间每15秒制作一张时间表。







以下是我目前所拥有的;感谢您提前的帮助



private void timer1_Tick(object sender,EventArgs e)

{



foreach(GateNumber1中的字符串G)

{

string path1 = string.Format(@C:\ Users \Ig \\ \\ Desktop\temp\Gate+ G +{0:yyMMddHHmmss}+.jpg,currentTime);

FileStream fs = File.Create(path1);

pictureBox1.Image.Save(fs,System.Drawing.Imaging.ImageFormat.Jpeg);

fs.Close();



}





foreach(GateNumber3中的字符串G)

{



string path1 = string.Format(@C:\Users\Ig\Desktop\temp\Gate+ G +{0:yyMMddHHmmss}+。 jpg,currentTime);

FileStream fs = File.Create(path1);

pictureBox1.Image.Save(fs,System.Drawing.Imaging.ImageFormat.Jpeg) ;

fs.Close();



}

解决方案

< blockquote c lass =FQ>

@ SkyHigh34写道:

附加信息:进程无法访问文件'C:\ Users \Ig \Desktop\temp\GateOne140823234809。 Jpg'因为它正在被另一个进程使用。

我会告诉你在这种情况下该怎么做,这很常见。这很容易调查。



首先,类似的问题在这里被多次询问,根据我的经验我知道:在大多数情况下,阻止过程是你的自己的过程。您可能忘记在同一个应用程序中处理/关闭某些内容。所以,首先,检查一下。要探索这种可能性,请参阅我过去的答案:

清除C#中的句柄 [ ^ ]。



在这个答案中,注意使用 / code>语句可以帮助您保证在使用后正确处理相应的文件系统对象,而不是保持文件锁定。



在某些情况下,你真的需要调查哪个进程拥有哪个文件。为此,我建议使用 Sysinternals Suite 中的一个实用程序。这组实用程序(以前来自 Winternals 公司,目前在Microsoft)是必须的对于任何开发人员,请参阅:

http://technet.microsoft.com/en -us / sysinternals / bb842062 [ ^ ],

http://technet.microsoft.com/en-us/sysinternals / bb545027 [ ^ ]。



您需要的实用程序是 handle.exe ,请参阅:

http://technet.microsoft.com/en-us/sysinternals/bb896655 [ ^ ]。



在您的情况下,您使用文件名参数:

 handle.exe< file_name> 





此实用程序将扫描所有类型的句柄,而不仅仅是文件句柄。对于文件,它将扫描与文件名匹配的所有文件句柄(因此它不必是完整路径名)并返回足以识别每个进程的信息,包括其 pid 。因此,如果您需要有关相关流程的更多信息,您还可以使用其他Sysinternals实用程序,特别是其 Process Explorer

http://technet.microsoft.com/en-us/sysinternals/bb896653 [ ^ ]。



祝你好运,

-SA


See more: C#
I am trying to schedule an image capture every 15 seconds; I have a string array of two gates. I have tried to set up intervals on the image capture, but I am not getting the results needed the closes I get is the image getting saved with a current timestamp; as the code run through the second sets of images after interval 15 seconds the new image takes on the time stamp of the first sets of images thus replacing original image with same timestamp but current image taken.

I would need to have every image on a schedule every 15 seconds taking the current time of the image creation.



below is what I have so far; Thank you for your help in advance

private void timer1_Tick(object sender, EventArgs e)
{

foreach (string G in GateNumber1)
{
string path1 = string.Format(@"C:\Users\Ig\Desktop\temp\Gate" + G + "{0:yyMMddHHmmss}" + ".jpg", currentTime);
FileStream fs = File.Create(path1);
pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
fs.Close();

}


foreach (string G in GateNumber3)
{

string path1 = string.Format(@"C:\Users\Ig\Desktop\temp\Gate" + G + "{0:yyMMddHHmmss}" + ".jpg", currentTime);
FileStream fs = File.Create(path1);
pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
fs.Close();

}

解决方案

@SkyHigh34 wrote:

Additional information: The process cannot access the file 'C:\Users\Ig\Desktop\temp\GateOne140823234809.Jpg' because it is being used by another process.

I'll tell you what to do in such situations, which a pretty usual. This is easy to investigate.

First of all, the similar question was asked here many times, and from this experience I know: in most cases the blocking process is your own process. You could have forgotten to dispose/close something in the same application. So, first of all, check it up. To explore this possibility, please see my past answer:
Clearing a Handle in C#[^].

In this answer, pay attention for the using of the using statement which helps you to guarantee that appropriate file system object is properly disposed after use, not keeping the file locked.

In some cases, you really need to investigate which process holds which file. For this, I recommend using one utility from the Sysinternals Suite. This set of utilities (formerly from Winternals company, presently at Microsoft) is a must-have for any developer, please see:
http://technet.microsoft.com/en-us/sysinternals/bb842062[^],
http://technet.microsoft.com/en-us/sysinternals/bb545027[^].

The utility you need is "handle.exe", please see:
http://technet.microsoft.com/en-us/sysinternals/bb896655[^].

In your case, you use it with file name parameter:

handle.exe <file_name>



This utility will scan all kinds of handles, not just file handles. For file, it will scan all file handles matching the file name (so it does not have to be a full path name) and return information sufficient to identify each process, including its pid. So, if you need more information on a process in question, you can also use other Sysinternals utilities, in particular, its Process Explorer:
http://technet.microsoft.com/en-us/sysinternals/bb896653[^].

Good luck,

—SA


这篇关于计时器时间表或间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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