C# 将信息返回主窗体的类delgate的实例

C# 将信息返回主窗体的类delgate的实例,c#,class,delegates,C#,Class,Delegates,我目前正在使用tweeinvi twitter库过滤推文。我有一个主窗体,它创建了TwitterAuthentication类的一个实例。在创建时,构造函数处理身份验证过程。然后,我从主窗体为单词hello创建一个过滤器,并尝试将此过滤流中的任何匹配项返回到主窗体,以便在一个简单的文本窗口中登录 因此,主要形式比特- private void authenticate(object sender, EventArgs e) { TwitterAuthentication

我目前正在使用tweeinvi twitter库过滤推文。我有一个主窗体,它创建了TwitterAuthentication类的一个实例。在创建时,构造函数处理身份验证过程。然后,我从主窗体为单词hello创建一个过滤器,并尝试将此过滤流中的任何匹配项返回到主窗体,以便在一个简单的文本窗口中登录

因此,主要形式比特-

private void authenticate(object sender, EventArgs e)
    {
        TwitterAuthentication user = new TwitterAuthentication();
        twitter_user.Text = user.username();

        string UserTxt = user.ToString();


        user.set_filter(log_output_update);


    }
    public void log_output_update(string s) //int y)
    {
        {
            string z = "[def]";

            //if (y == 0) { z = "[SYS] "; }
            //if (y == 1) { z = "[IN] "; }
            //if (y == 2) { z = "[OUT] "; }
            //if (y == 3) { z = "[**ERROR**] It may be Phils Coding! Error - "; }

            string time = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");

            //if (y == 0) { log_output_window.SelectionColor = Color.White; }
            //if (y == 1) { log_output_window.SelectionColor = Color.Blue; }
            //if (y == 2) { log_output_window.SelectionColor = Color.Green; }
            //if (y == 3) { log_output_window.SelectionColor = Color.Red; }

            log_output_window.AppendText(z + time + " " + s + System.Environment.NewLine);
            log_output_window.ScrollToCaret();
        }
    }
全班同学(我已经用x划掉了证书)——

如果能帮我把这个传回来,那就太好了!另外,如果我想从类中传回set_filter方法之外的任何标准文本,这将如何实现


提前谢谢

您使用的是Process类,其中与应用程序通信的唯一方式是使用标准输入/输出。最好使用可以直接与服务器通信的HttpRequest。@使用Http请求限制了我可以发出的请求量,这是一个更简洁的解决方案,流将在发布时实时匹配与我的筛选器匹配的任何推文。为什么限制会有任何不同。当建立连接时,服务器只获取客户端的IP,这与httprequest和Tweenvi twitter库之间没有区别。@jdweng Ok我认为不使用流和直接发出请求,使用请求方法而不是流,twitter的os结果数量是有限制的。另外,如果发出http请求,如何继续发出该请求以获取实时数据?您可以提供的任何其他反馈都将受到赞赏。@jdweng检查后,GET和POST-https请求方法受到限制,而流式API的限制更小。因此,在此应用程序中使用流式API是有意义的。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Diagnostics;
using System.Windows.Forms;
using Tweetinvi;
using Tweetinvi.Models;
using System.Drawing;


public class TwitterAuthentication
{
public delegate void Callback_Log_Tweet(string x);
public TwitterAuthentication()
{

    IAuthenticationContext _authContext;
    var appCredentials = new TwitterCredentials("x", "x");
    _authContext = AuthFlow.InitAuthentication(appCredentials);



    using (var client = new WebClient())
    {
        try
        {
            using (var Stream = client.OpenRead("http://www.google.com"))
            {
                Process.Start(_authContext.AuthorizationURL);

                //open pin box and enter pin
                SocialiFace_v2.PinAuth Pin = new SocialiFace_v2.PinAuth();
                Pin.ShowDialog();
                System.Console.WriteLine(Pin.Pin_Auth);
                var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(Pin.Pin_Auth, _authContext);
                Auth.SetCredentials(userCredentials);

                try
                {
                    var authenticateduser = User.GetAuthenticatedUser();
                    return;
                }
                catch (Tweetinvi.Exceptions.TwitterNullCredentialsException)
                {
                    MessageBox.Show("Error Authenticating");
                    return;
                }
            }
            //Callback_Log_Tweet("Logged In...."");

        }
        catch (Exception)
        {
            MessageBox.Show("Error Authenticating2");
            return;
        }

    }
}

public string username()
{
    try
    {
        var authenticateduser = User.GetAuthenticatedUser();
        string handle = authenticateduser.Name;
        return handle;
    }
    catch (Exception)
    {
        MessageBox.Show("Error getting username");
        return null;
    }
}

public void set_filter(Callback_Log_Tweet x)
{
    var stream = Stream.CreateFilteredStream();
    stream.AddTrack("Hello");
    stream.MatchingTweetReceived += (sender, args) =>
    {
        //Send back to delgate, and to print output delegate
       x("A tweet containing 'Hello' has been found; the tweet is '" + args.Tweet + "'");

    };
}