ฉันกำลังพยายามสร้างเธรดใหม่โดยใช้วิธีการจากไฟล์ cs อื่น แต่ฉันได้รับข้อผิดพลาดนี้
นี่คือรหัส
โปรแกรม.cs:
using HangManSharp;
Backend _backend = new Backend();
Thread initThread = new Thread(_backend.getWord); //Error CS1503 Argument 1: cannot convert from 'method group' to 'ParameterizedThreadStart'
แบ็กเอนด์.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HangManSharp
{
internal class Backend
{
public string getWord()
{
const int wordCount = 50000;
int randomWordNum = Random.Shared.Next(wordCount);
try
{
StreamReader sr = new StreamReader("words");
for (int i = 0; i < wordCount; i++)
{
sr.ReadLine();
if (i == randomWordNum)
{
return sr.ReadLine();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Environment.Exit(1);
}
return null;
}
}
}
ฉันต้องการใช้มัลติเธรดเพราะฉันต้องการแสดงหน้าจอการโหลดในขณะที่ได้รับคำ
ฉันลองใส่ทุกอย่างลงในไฟล์เดียวกันแล้ว แต่ก็ใช้งานไม่ได้
ขอบคุณล่วงหน้า