小编Ela*_*ahe的帖子

如何在一个过程中暂停然后在它之后返回值?

我正在开发一个C#项目,希望在一个程序中做一个小的暂停约2秒.

其实我已经尝试过使用Invoke,但是如你所知,我们不能在类中使用它这种程序.

这是我的代码以获取更多详细信息:

public class GenerateFile
{

    public CSPFEnumration.ProcedureResult GenerateFaxFile(string Daftar_No, string Channelno, string NationalCode)
    {
        string script = string.Format(" DECLARE @RC INT " +
                                        " DECLARE @Daftar_No INT = '{0}' " +
                                        " DECLARE @hokm_type_code INT = 100 " +
                                        " DECLARE @Channelno INT = '{1}' " +
                                        " DECLARE @Id_No BIGINT = '{2}' " +
                                        " EXEC @rc = [dbo].[Hokm_with_type] @Daftar_No, @hokm_type_code, @Channelno, @Id_No ",
                                        Daftar_No,
                                        Channelno,
                                        NationalCode);
        try
        {
            IEnumerable<string> commandStrings = Regex.Split(script, @"^\s*GO\s*$",
                                                    RegexOptions.Multiline | RegexOptions.IgnoreCase); …
Run Code Online (Sandbox Code Playgroud)

c# pause

13
推荐指数
2
解决办法
1106
查看次数

如何在openCV python 2.7中添加"Tracker"

我正在使用python 2.7和opencv 3.1我想运行一个跟踪对象的代码:

import cv2
import sys

if __name__ == '__main__' :

    # Set up tracker.
    # Instead of MIL, you can also use
    # BOOSTING, KCF, TLD, MEDIANFLOW or GOTURN

    tracker = cv2.Tracker_create("MIL")

    # Read video
    video = cv2.VideoCapture("videos/chaplin.mp4")

    # Exit if video not opened.
    if not video.isOpened():
        print "Could not open video"
        sys.exit()

    # Read first frame.
    ok, frame = video.read()
    if not ok:
        print 'Cannot read video file'
        sys.exit()

    # Define an initial bounding box
    bbox = …
Run Code Online (Sandbox Code Playgroud)

python opencv tracker

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

如何在WPF中的选项卡控件中添加用户控件

下面的文章展示了如何在WPF中创建动态选项卡,在每个选项卡中它将只添加一个文本框.

private TabItem AddTabItem()
{
    int count = _tabItems.Count;

    // create new tab item
    TabItem tab = new TabItem();

    tab.Header = string.Format("Tab {0}", count);
    tab.Name = string.Format("tab{0}", count);
    tab.HeaderTemplate = tabDynamic.FindResource("TabHeader") as DataTemplate;

    tab.MouseDoubleClick += new MouseButtonEventHandler(tab_MouseDoubleClick);

    // add controls to tab item, this case I added just a textbox
    TextBox txt = new TextBox();

    txt.Name = "txt";
    tab.Content = txt;
    // insert tab item right before the last (+) tab item
    _tabItems.Insert(count - 1, tab);

    return tab;
}
Run Code Online (Sandbox Code Playgroud)

http://www.codeproject.com/Articles/493538/Add-Remove-Tabs-Dynamically-in-WPF …

c# wpf tabitem

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

在 Visual Studio 中创建大括号的快捷方式

很多时候我的 if 条件只有一行,如下所示:

if (true)
    // my single code
Run Code Online (Sandbox Code Playgroud)

但有时,我想将 if 条件扩展到 2 个或更多代码,所以我应该使用大括号。

if (true)
{ 
    //do something
}
Run Code Online (Sandbox Code Playgroud)

我想知道是否有将第一个代码更改为第二个代码的快捷方式?

c# shortcut braces visual-studio

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

当url没有以"/"结尾时,如何使用HttpListener?

我想听一个获取一些信息的网址.所以我的代码是这样的:

public static void SimpleListenerExample(string[] prefixes)
{
    HttpListener listener = new HttpListener();
    // Add the prefixes. 
    foreach (string s in prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    //Console.WriteLine("Listening...");
    // Note: The GetContext method blocks while waiting for a request. 
    HttpListenerContext context = listener.GetContext();
    HttpListenerRequest request = context.Request;
    // Obtain a response object.
    HttpListenerResponse response = context.Response;
    // Construct a response. 
    string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";
    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
    // Get a response stream and write the response to it.
    response.ContentLength64 …
Run Code Online (Sandbox Code Playgroud)

c# httplistener

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

如何获取套接字异常值

我使用了一个用于创建套接字连接的组件。现在,我有一个客户端和服务器,可以通过该组件相互连接。但我的问题是:当发生某些错误时,我得到了如下消息:

System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it
Run Code Online (Sandbox Code Playgroud)

我想知道此代码(0x80004005)与MSDN WebSite中的 Winsock错误代码之间是否有任何关系 ?此代码是什么意思?它显示值错误代码吗?或类似的东西?

实际上我想获得相关的值,10061但我不知道如何通过字符串值来获得它。感谢您的帮助。

c# socketexception

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

插入记录后如何从SQL服务器获取标识值

我在我的数据库中添加了一条带有identity值的记录。我想在插入后获取标识值。我不想通过存储过程来做到这一点。

这是我的代码:

SQLString = " INSERT INTO myTable ";
SQLString += " (Cal1, Cal2, Cal3, Cal4) ";
SQLString += " VALUES(N'{0}',N'{1}',N'{2}',N'{3}') ";
SQLString = string.Format(SQLString, Val1, Val2, Val3, Val4);
SQLString += " Declare @_IdentityCode INT SET @_IdentityCode = @@IDENTITY RETURN @_IdentityCode";

int result;

public int DoCommand2(string sql)
{
        con = new SqlConnection();
        cmd = new SqlCommand();
        da = new SqlDataAdapter();
        cmd.Connection = con;
        da.SelectCommand = cmd;

        string cs = GlobalConstants.SqlConnectionString;
        con.ConnectionString = cs;

        cmd.CommandText = sql;
        int i …
Run Code Online (Sandbox Code Playgroud)

.net c# sql sql-server identity

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

C#:如何使用Thread并知道什么时候完成线程工作?

我在C#win表单项目中阅读了UNSEEN电子邮件.有些时候有附加文件,下载有一些时间,所以我的项目的UI将在下载完成期间锁定.我使用ThreadPool来解决这个问题.

这是我的代码:

    System.Threading.ThreadPool.QueueUserWorkItem((o) =>
    {
        for (int i = 0; i < lstEmailAddress.Count; i++)
        {
            Get(imap[i], lstEmailAddress[i].MailBox, out Emails[i]);
        }

        this.BeginInvoke(new Action(() =>
        {
            for (int i = 0; i < lstEmailAddress.Count; i++)
            {
                for (int j = 0; j < Emails[i].Count; j++)
                {
                    Database.EmailRecieve_Insert(Emails[i][j]);
                }

                arrEmailUserControl[i].txtRecievedCount.Text = (Convert.ToInt32(arrEmailUserControl[i].txtRecievedCount.Text) + Emails[i].Count).ToString();
            }

        }));
    });
Run Code Online (Sandbox Code Playgroud)

这是我使用的Get方法:

private bool Get(Imap4Client imap, string[,] MailBox, out List<EmailStruct> Emails)
    {
        Emails = new List<EmailStruct>();
        try
        {
            for (int i = 0; i < MailBox.GetLength(0); i++) …
Run Code Online (Sandbox Code Playgroud)

c# multithreading threadpool

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

按Tab键在userControl中按顺序选择按钮

我有它的一些按钮的用户控件(btnNew,btnCancel,btnEdit).

我在另一个项目中使用了这个UserControl.当我按下此项目中的Tab键时,选择按钮不会定期更改!

例如,我希望如果用户按下Tab键,首先btnNew选择按钮,然后选择btnEdit按钮,最后选择btnCancel按钮.

但是在这个项目中,当按下Tab键时,btnCancel首先选择按钮.

我想自己管理按钮的Tab键顺序,而不是使用默认值.我怎样才能做到这一点?

谢谢...

c# winforms

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

如何知道dll事件何时被触发

我创建了一个包含此事件处理程序的DLL:

public void tcp1_Data(object sender, Sockets.DataEventArgs e)
{
  Tcp tcp = (Tcp)sender;

  response = "Socket Connection" + tcp.Tag.ToString() + " replied : " + e.Data.ToString();

  tcp.Close();
}
Run Code Online (Sandbox Code Playgroud)

当服务器在套接字连接中写入一些东西时,这将触发 所以,通过这个,我可以读取socket上的数据.

我在另一个项目中使用了这个dll.我想在我的项目(使用dll)中知道服务器在套接字连接上写入数据的确切时间.正如你在tcp1_Data事件中看到的那样,我将结果设置为响应变量,在主项目中(使用了dll),我检查了这个变量polling(如果响应不为null,则表示此事件被触发).但它不是我想要的.我不想一直检查这个变量.

还有其他方法吗?


我试过这个,因为@ThorstenDittmar说:

我的dll项目(名称为ClientSample)包含:

  1. TheClassInDLL Class

    public class TheClassInDLL
    {
    
        public event EventHandler<MyEventArgs> DataEventCalled;
    
        public void tcp1_Data(object sender, Sockets.DataEventArgs e)
        {
            Tcp tcp = (Tcp)sender;
    
            // Note: LOCAL variable
            string myresponse = "Socket Connection" + tcp.Tag.ToString() + " replied : " + e.Data.ToString();
    
            // Call the new event here
            if (DataEventCalled …
    Run Code Online (Sandbox Code Playgroud)

c# dll events

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