小编Kay*_*ayX的帖子

'method'没有重载匹配委托'System.EventHandler'

我正在尝试构建一个程序,一旦按下按钮,每5秒钟将执行一次该功能(OnTimed).

以下是目前的代码:

private void bntCapture_Click(object sender, RoutedEventArgs e)
{ 
    DispatcherTimer t1 = new DispatcherTimer();
    t1.Interval = TimeSpan.FromMilliseconds(5000);
    t1.IsEnabled = true;
    t1.Tick += new EventHandler(OnTimed);
    t1.Start();
}

void OnTimed(object sender, ElapsedEventArgs e)
{

    imgCapture.Source = imgVideo.Source;
    System.Threading.Thread.Sleep(1000);
    Helper.SaveImageCapture((BitmapSource)imgCapture.Source);
} 
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,它显示错误:

"'方法'没有重载匹配委托'System.EventHandler'

.net c# wpf compiler-errors

6
推荐指数
1
解决办法
4万
查看次数

如何防止将重复数据插入SQL Server表?

我有一系列需要写入SQL的数据,我应该怎么做才能检查SQL中的数据以防止相同的数据插入到表中?

要插入的示例数据:

David  
James  
John  
Run Code Online (Sandbox Code Playgroud)

如果第四个数据John再次出现,我希望系统跳过重复记录(John).

到目前为止,我有:

SqlConnection myCnn = new SqlConnection(cnn);
String _state = "Insert into CamNo1(platename, date, camID, path, filename) OUTPUT INSERTED.platename values(@msg, getdate(), @camID, @path, @filename)";
SqlCommand _Query = new SqlCommand(_state, myCnn);

_Query.Parameters.AddWithValue("@msg", msg);
_Query.Parameters.AddWithValue("@camID", camID);
_Query.Parameters.AddWithValue("@path", imageFile);
_Query.Parameters.AddWithValue("@filename", name);

try
{
   myCnn.Open();
   string checkname = (string)_Query.ExecuteScalar();
   myCnn.Close();

   getcheckname = checkname;
   Console.WriteLine("OK");
}
catch (Exception)
{
}
Run Code Online (Sandbox Code Playgroud)

我得到了最后插入的字符串值checkname,我应该检查数据?

c# sql sql-server sql-server-2008

5
推荐指数
2
解决办法
2万
查看次数

C#System.OutOfMemoryException未处理

我使用foreach来读取文件夹中的所有图像

        string[] filePaths = Directory.GetFiles(Workspace.InputFolder, "*.*");
        foreach (string imageFile in filePaths)
        {
            // Some Process here, the output are correct, just after output 
               the error happen
        }
Run Code Online (Sandbox Code Playgroud)

但它出来了错误

System.OutOfMemoryException was unhandled
  Message=Out of memory.
  Source=System.Drawing 
Run Code Online (Sandbox Code Playgroud)

问题是由foreach循环引起的,在进程完成后保持循环吗?我应该怎样做才能释放记忆?谢谢.

c# out-of-memory

1
推荐指数
1
解决办法
4310
查看次数