【发布时间】:2018-05-09 14:55:46
【问题描述】:
我在将我为 Windows 创建的 C# 项目转换为 Android Xamarin 时遇到问题。我在网上搜索了有关 RichTextBox 以及用于构建 Windows 版本程序的其他功能和组件的任何解决方案,但除了一个主题 here 外,我找不到任何好的解决方案,但这对我没有帮助。 如果没有办法添加诸如richtextbox之类的东西,是否还有其他支持.Lines的文本框,以便我可以获得正确的行号?
这是我的代码的一部分:
private void ThreadTask1()
{
string link = "http://example.com/music-today.php";
int TimeToWait = 300;
int check_ID = 0;
string ParsedResult = null;
HtmlAgilityPack.HtmlDocument doc = null;
HtmlWeb web1 = new HtmlWeb();
while (true) {
ParsedResult = "";
RichTextBox1.Clear();
RichTextBox2.Clear();
web1.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)";
web1.UsingCache = false;
web1.UseCookies = true;
doc = web1.Load(link);
HtmlNode div = doc.DocumentNode.SelectSingleNode("//div[@class='latest-song14']");
if ((div != null)) {
ParsedResult = div.InnerText.Trim();
RichTextBox1.Text = ParsedResult;
RichTextBox2.Text = RichTextBox1.Lines[0];
if (!RichTextBox2.Text.Contains("dj")) {
Sound vol = new Sound("nircmdc.exe");
vol.setVol(40);
while (true) {
MyMusicInformer.My.MyProject.Computer.Audio.Play("C:\\Windows\\media\\Alarm01.wav", AudioPlayMode.Background);
System.Threading.Thread.Sleep(700);
MyMusicInformer.My.MyProject.Computer.Audio.Play("C:\\Windows\\media\\Alarm01.wav", AudioPlayMode.Background);
System.Threading.Thread.Sleep(700);
MyMusicInformer.My.MyProject.Computer.Audio.Play("C:\\Windows\\media\\Alarm01.wav", AudioPlayMode.Background);
System.Threading.Thread.Sleep(5000);
}
} else {
check_ID = check_ID + 1;
RichTextBox2.Text = "No new song yet. Try (" + check_ID.ToString() + ")";
}
}
System.Threading.Thread.Sleep(TimeToWait * 1000);
}
}
private Thread trd1;
private void Form1_Load(object sender, EventArgs e)
{
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
trd1 = new Thread(ThreadTask1);
trd1.IsBackground = true;
trd1.Start();
}
我只想在有新歌更新时得到通知。在 Visual Studio 中,我只能看到“多行文本”选项,但它不能解决我的问题。
感谢您的宝贵时间。
【问题讨论】:
标签: c# android windows visual-studio xamarin