最后一个是Type或命名空间定义,或者是期望的文件结尾
而另一个约为private static void OnTimedEvent1(object source, ElapsedEventArgs e)
的一半{预期
感谢
和实际的CODE :(我把错误放在这里)
namespace Gmail_final_prep
{
public class Gmail_FP
{
private static System.Timers.Timer gTimer;
public static void GMain()
{
gTimer = new System.Timers.Timer(2000);
// Hook up the Elapsed event for the timer.
gTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent1);
gTimer.Interval = 2000;
gTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
// If the timer is declared in a long-running method, use
// KeepAlive to prevent garbage collection from occurring
// before the method ends.
//GC.KeepAlive(gTimer);
}
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bytes = encoding.GetBytes(sAscii);
return System.Convert.ToBase64String(bytes, 0, bytes.Length);
}
public static string CheckMail()
{
string result = "0";
try
{
var url = @"https://gmail.google.com/gmail/feed/atom";
var USER = "usr";
var PASS = "pss";
var encoded = TextToBase64(USER + ":" + PASS);
var myWebRequest = HttpWebRequest.Create(url);
myWebRequest.Method = "POST";
myWebRequest.ContentLength = 0;
myWebRequest.Headers.Add("Authorization", "Basic " + encoded);
var response = myWebRequest.GetResponse();
var stream = response.GetResponseStream();
XmlReader reader = XmlReader.Create(stream);
System.Text.StringBuilder gml = new System.Text.StringBuilder();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
if (reader.Name == "fullcount")
{
gml.Append(reader.ReadElementContentAsString()).Append(",");
//result = reader.ReadElementContentAsString();
//return result;
}
}
Console.WriteLine(gml.ToString());
}
catch (Exception ee) { Console.WriteLine(ee.Message); }
return result;
}
}
}
} // Type or namespace definition, or end-of-file expected here
答案 0 :(得分:7)
你在另一种方法中有一个方法。
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
这可能就是您要做的事情 - 您希望从事件处理程序中调用 CheckMail()
。
using System;
using System.Net;
using System.Timers;
using System.Xml;
namespace Gmail_final_prep
{
public class Gmail_FP
{
private static System.Timers.Timer gTimer;
public static void GMain()
{
gTimer = new System.Timers.Timer(2000);
// Hook up the Elapsed event for the timer.
gTimer.Elapsed += OnTimedEvent1;
gTimer.Interval = 2000;
gTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
// If the timer is declared in a long-running method, use
// KeepAlive to prevent garbage collection from occurring
// before the method ends.
//GC.KeepAlive(gTimer);
}
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
CheckMail();
}
public static string TextToBase64(string sAscii)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bytes = encoding.GetBytes(sAscii);
return System.Convert.ToBase64String(bytes, 0, bytes.Length);
}
public static string CheckMail()
{
string result = "0";
try
{
var url = @"https://gmail.google.com/gmail/feed/atom";
var USER = "usr";
var PASS = "pss";
var encoded = TextToBase64(USER + ":" + PASS);
var myWebRequest = HttpWebRequest.Create(url);
myWebRequest.Method = "POST";
myWebRequest.ContentLength = 0;
myWebRequest.Headers.Add("Authorization", "Basic " + encoded);
var response = myWebRequest.GetResponse();
var stream = response.GetResponseStream();
XmlReader reader = XmlReader.Create(stream);
System.Text.StringBuilder gml = new System.Text.StringBuilder();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
if (reader.Name == "fullcount")
{
gml.Append(reader.ReadElementContentAsString()).Append(",");
//result = reader.ReadElementContentAsString();
//return result;
}
}
Console.WriteLine(gml.ToString());
}
catch (Exception ee) { Console.WriteLine(ee.Message); }
return result;
}
}
} // Type or namespace definition, or end-of-file expected here
答案 1 :(得分:3)
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
{
这不合法 - 你不能在另一个方法中嵌入一个方法。
答案 2 :(得分:1)
我想知道这部分是做什么的:
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
你的问题可能就在这里。