TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
G scerri
NA
3
2.4k
Threads
Jan 11 2011 1:06 PM
i am a beginner to C# i am trying to type some code for threading, and now i came across this error:"
A field initializer cannot reference the non-static field, method, or property 'Thread_test.Form1.task()' "
and here is my code in c#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Thread_test
{
public partial class Form1 : Form
{
Thread process = new Thread(new ThreadStart(task));
public void task()
{
int a = 0;
for (; ; )
{
a = a + 1;
textBox1.Text = Convert.ToString(a);
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
process.Start();
}
}
}
Thanks for your help !-)
Reply
Answers (
2
)
Windows Phone 7 Feedback
Dotnet Using C#