[Gtk-sharp-list] A first go at gtk-sharp

Brad Taylor brad@getcoded.net
Sat, 26 Mar 2005 12:49:04 -0800

Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable


> I have created a first gtk-sharp program.Programming in C-sharp using
> GTK is surprisingly easy once you get the hang of it. My program is a
> tiny convers network client which uses networking and threading.  The
> GTK GUI is updated using the recommended ThreadNotify function.
> Some parts I don't quite understand: why do I need "Thread.Sleep (50)"
> in ReceiveChat ()? If I leave it out, the TextView gets updated  with
> only part of the nework information,especially when received network
> information consists of more than about 10 lines. Adding a Sleep here
> would mean that a slower system would need more sleep than a fast
> system. How do I avoid this?

What this looks like is a concurrency issue.  It seems that the call

  b.Insert (b.EndIter, data);

is being called and before it even finishes, ready () is called again.
Between the first call and the second call, internal variables are being
updated but text and the EndIter are not, giving the error=20

  (<unknown>:13364): Gtk-CRITICAL **: gtk_text_buffer_insert: assertion
`text !=3D NULL' failed

The sleep command gives the buffer enough time to update text and
doesn't pound gtk.  The way that I overcame the problem was to lock the
buffer on that first statement so that multiple instances of ready ()
couldn't update the buffer at the same time like so:

	private void ready ()
                TextMark EndMark;

                lock (b) {
	                b.Insert (b.EndIter, data);

                b.Insert (b.EndIter, "\r\n");
                EndMark =3D b.CreateMark ("end", b.EndIter, false);
                tv.ScrollToMark (EndMark, 0.4, true, 0.0, 1.0);
                b.DeleteMark (EndMark);

This fixes the problem without a sleep, but does not visually change the
speed at which it updates.  Maybe somebody who has more knowledge about
the inner workings of gtk+ (like Todd, who surely will wake up from
troll mode just to slap me with a big fish) could clarify this.

Hope this helps.


Brad Taylor
Genome Software LLC

Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

Version: GnuPG v1.2.5 (GNU/Linux)