wiec dostaje gdy odpale program to narysuje troszeczke i dostaje takiego errora:
Obiekt jest obecnie używany gdzie indziej(InvalidOperationException was unhandled)
przy linijce z g = Graphics.FromImage(bmp) lub Application.Run(new Form1());
Wstawie cały kod to może bedzie bardziej wiadomo ocb
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 neuron1
{
public partial class Form1 : Form
{
Bitmap bmp;
public Thread Rysuj;
public Tneuron n1 = new Tneuron(3);
public Tneuron n2 = new Tneuron(3);
public Tneuron n3 = new Tneuron(3);
public Tneuron n4 = new Tneuron(3);
public Tneuron n5 = new Tneuron(3);
public Tneuron n6 = new Tneuron(6);
public Graphics g;
public Form1()
{
InitializeComponent();
System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = false;
}
void watek()
{
double[] wejscia1 = new double[3];
double[] wejscia2 = new double[6];
wejscia1[0] = 1;
wejscia2[0] = 1;
int x;
int y;
Random losuj = new Random();
double odpowiedz;
while (true)
{
g = Graphics.FromImage(bmp);
for (int i = 0; i < 100; i++)
{
//wejscie
x = losuj.Next(513);
y = losuj.Next(513);
wejscia1[1] = ((double)x - 256 / 256);
wejscia1[2] = ((double)y - 256 / 256);
wejscia1[2] = 1 - wejscia1[2];
//warstwa 1
if (radioFunkcjaA.Checked)
{
wejscia2[1] = n1.ObliczWyjscie(wejscia1, 'A');
wejscia2[2] = n2.ObliczWyjscie(wejscia1, 'A');
wejscia2[3] = n3.ObliczWyjscie(wejscia1, 'A');
wejscia2[4] = n4.ObliczWyjscie(wejscia1, 'A');
wejscia2[5] = n5.ObliczWyjscie(wejscia1, 'A');
//wyjscie
odpowiedz = n6.ObliczWyjscie(wejscia2, 'A');
}
else
{
wejscia2[1] = n1.ObliczWyjscie(wejscia1, 'F');
wejscia2[2] = n2.ObliczWyjscie(wejscia1, 'F');
wejscia2[3] = n3.ObliczWyjscie(wejscia1, 'F');
wejscia2[4] = n4.ObliczWyjscie(wejscia1, 'F');
wejscia2[5] = n5.ObliczWyjscie(wejscia1, 'F');
//wyjscie
odpowiedz = n6.ObliczWyjscie(wejscia2, 'F');
}
//rysowanie
Pen z = new Pen(Color.Green, 1.0f);
Pen r = new Pen(Color.Red, 1.0f);
if (odpowiedz > 0)
{
g.DrawEllipse(z, x, y, 1, 1);
}
else
{
g.DrawEllipse(r, x, y, 1, 1);
}
} //for koniec
try { pictureBox1.Image = bmp; }
catch { }
pictureBox1.Invalidate();
g.Dispose();
}
}
private void buttonStart_Click(object sender, EventArgs e)
{
Thread Rysuj = new Thread(new ThreadStart(watek));
Rysuj.Priority = ThreadPriority.Normal;
Rysuj.IsBackground = true;
Rysuj.Start();
buttonStart.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
}
private void button_zamknij_Click(object sender, EventArgs e)
{
Close();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 forma2 = new Form2(this);
forma2.Show();
}
}
}