Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I keep getting "Non-invocable member cannot be treated like a method" why?

C#
<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()
        {
        }
    }
}
Posted
Updated 12-Jan-15 1:03am
v2
Comments
Kornfeld Eliyahu Peter 12-Jan-15 6:56am    
Can you help us by pointing out the exact line of the error?
Garth J Lancaster 12-Jan-15 6:58am    
might be helpful to include where the compiler is indicating the error/complaining - mark it in bold or comment it - please go back and edit your code to show this
kbhtech 12-Jan-15 7:07am    
Thanks, I just included the form that the errors are posting them self on. :) I appreciate you for taking a glance. (its BIG BOLD AND UNDERLINED)

Try:
comms.OnCookies += new transmition.Cookie_Handler(comms_OnCookies);
...
 
Share this answer
 
hmm, well, for a start, Im not sure about this (and the similar instances) being static

C#
static void comms_OnCookies(object a, Cookies e)
{

}


usually it would be public would it not ?
 
Share this answer
 
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 :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900