可以帮我解决这个问题吗? [英] Can somone help me fix this?

查看:71
本文介绍了可以帮我解决这个问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直得到不可调用的成员不能被视为一种方法为什么?



I keep getting "Non-invocable member cannot be treated like a method" why?

<code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;

namespace Neopets.classes.communications
{
    public class LoggedOut : EventArgs
    {
        private bool status;

        public LoggedOut(bool status)
        {
            this.status = status;
        }

        public bool Status
        {
            get
            {
                return status;
            }
        }
    }
    public class Offline : EventArgs
    {
        private bool status;

        public Offline(bool status)
        {
            this.status = status;
        }

        public bool Status
        {
            get
            {
                return status;
            }
        }
    }
    public class Cookies : EventArgs
    {
        private string data;

        public Cookies(string data)
        {
            this.data = data;
        }

        public string Data
        {
            get
            {
                return data;
            }
        }
    }

    public class Response : EventArgs
    {
        private string data;

        public Response(string data)
        {
            this.data = data;
        }

        public string Data
        {
            get
            {
                return data;
            }
        }
    }

    class transmition
    {
        public delegate void Response_Handler(Object myobject, Response source);
        public event Response_Handler OnResponse;

        public delegate void Cookie_Handler(Object myobject, Cookies cookies);
        public event Cookie_Handler OnCookies;

        public delegate void Offline_Handler(Object myobject, Offline connected);
        public event Offline_Handler OnOffline;

        public delegate void LoggedOut_Handler(Object myobject, LoggedOut true_false);
        public event LoggedOut_Handler OnLoggedOut;


        public int Navigate(string page = "", string formparams = "", string cookieheader = "")
        {
            try
            {
                using (var client = new WebClient())
                using (var stream = client.OpenRead("http://www.google.com"))
                {
                    // Do Nothing :)
                }
            }
            catch
            {
                Offline connected = new Offline(false);
                OnOffline(this, connected);
                return 0;
            }

            WebRequest req = WebRequest.Create("http://www.neopets.com/" + page);
            string src = "";

            if (cookieheader != "")
            {
                req.Headers.Add("Cookie", cookieheader);
                WebResponse getResponse = req.GetResponse();
                using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
                {
                    src = sr.ReadToEnd();
                }
            }
            else
            {
                byte[] bytes = Encoding.ASCII.GetBytes(formparams);
                req.ContentType = "application/x-www-form-urlencoded";
                req.Method = "POST";
                req.ContentLength = bytes.Length;

                using (Stream os = req.GetRequestStream())
                {
                    os.Write(bytes, 0, bytes.Length);
                }

                WebResponse resp = req.GetResponse();
                cookieheader = resp.Headers["Set-cookie"];

                Cookies cookies = new Cookies(cookieheader);
                OnCookies(this, cookies);

                using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
                {
                    src = sr.ReadToEnd();
                }
            }

            if (src.Contains("<form method=\"post\" action=\"/login.phtml\">"))
            {
                LoggedOut loggedout = new LoggedOut(true);
                OnLoggedOut(this, loggedout);
            }

            Response source = new Response(src);
            OnResponse(this, source);

            return 1;
        }
    }
}

=====================THE SERVICE THE EXECUTES THE EVENT HANDLERS===================

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using Neopets.classes.communications;

namespace Neopets.services
{
    public partial class market : ServiceBase
    {
        private transmition comms = new transmition();
        private string cookies;
        private bool loggedout;
        private bool offline;
        private string response;

        public string Response
        {
            get { return response; }
        }

        public string Cookies
        {
            get { return cookies;  }
        }

        public market()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            if (args.Count() == 1 )
            {
                if (args[0] == "debug")
                {
                    forms.Debugger debug = new forms.Debugger();
                    debug.Show();
                }
            }

           
<big>            comms.OnCookies += transmition.Cookie_Handler(comms_OnCookies);
            comms.OnLoggedOut += transmition.LoggedOut_Handler(comms_logout);
            comms.OnOffline += transmition.Offline_Handler(comms_offline);
            comms.OnResponse += transmition.Response_Handler(comms_response);</big>

            comms.Navigate();
        }

        static void comms_OnCookies(object a, Cookies e)
        {
            
        }
        static void comms_logout(object a, LoggedOut e)
        {
            
        }

        static void comms_offline(object a, Offline e)
        {
            
        }

        static void comms_response(object a, Response e)
        {
            
        }
        protected override void OnStop()
        {
        }
    }
}

推荐答案

尝试:

Try:
comms.OnCookies += new transmition.Cookie_Handler(comms_OnCookies);
...


嗯,好吧,首先,我不确定这个(和类似的例子)是静态的



hmm, well, for a start, Im not sure about this (and the similar instances) being static

static void comms_OnCookies(object a, Cookies e)
{

}





通常它会公开吗?



usually it would be public would it not ?


OriginalGriff的建议解决了部分问题,除了他的建议我不得不改变静态空洞保护虚拟空洞。随意根据需要使用它。我喜欢这个剧本:)
OriginalGriff's advice solved part of the problem, an addition to his advice I had to change the static voids to protected virtual voids. Feel free to use this as needed. I like this script :)


这篇关于可以帮我解决这个问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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