[MonoDevelop] Gtk.TextView question [SOLVED]

Michael Hutchinson m.j.hutchinson at gmail.com
Fri Jul 9 18:34:41 EDT 2010


On Fri, Jul 9, 2010 at 6:40 PM, Aniello Di Nardo
<dinardo at creasoftware.net> wrote:
>> On Fri, Jul 9, 2010 at 2:57 PM, Aniello Di Nardo
>> <dinardo at creasoftware.net> wrote:
>>>
>>> Hi!
>>>
>>> I'm building a little chat mono gtk# application and I've some question
>>> about the Gtk.TextView.
>>>
>>> I use the follow code to add a line into the Gtk.TextView widget...
>>>
>>> ...
>>> Gtk.TextView txvMonitor = new Gtk.TextView()
>>> ...
>>> void addToMonitor(string textToAdd) {
>>>   TextIter mIter = txvMonitor.Buffer.EndIter;
>>>   txvMonitor.Buffer.Insert(ref mIter, textToAdd);
>>>   txvMonitor.Buffer.EndIter.
>>>   txvMonitor.ScrollToIter(txvMonitor.Buffer.EndIter, 0, false, 0, 0);
>>> }
>>>
>>>
>>> when the text fill the visible area of the Gtk.TextView widget, the
>>> scroll
>>> bars do not move...
>>>
>>> why the refresh of the Gtk.TextView widget occour only (or any time) when
>>> i
>>> click on it?
>>>
>>> often... the application crash when "void addToMonitor" occour! Why?
>>> There
>>> is something wrong with the code?
>>>
>>> is possible set the background and the foreground color of the
>>> Gtk.TextView
>>> widget?
>>>
>>> There is a more simple widget as the "single-line Entry widget", but
>>> multi-line width the scroll bars?
>>>
>>> Thanks for any replies?
>>
>> Are you adding the text from a thread?
>>
>> --
>> Michael Hutchinson
>> http://mjhutchinson.com
>>
>
> Not directly from a thread.
>
> So ...
> There is a class "Socket" that raises the "OnDataReceived" event.
> The event is listened in the main window class and text is added to the
> Gtk.TextView from the "void addToMonitor".
> In the "socket" class, however, uses the following code for interact with
> System.Net.Sockets.Socket class:
>
> ...
> m_pfnCallBack = new AsyncCallback (OnDataReceived)
> ...
>
> this reminds me of something similar to a Thread, so I changed the previous
> code in the following code, adding the Gtk.Application.Invoke (delegate
> {...}) used for refresh the GUI's objects when there is a thread...
>
> void addToMonitor(string sToAdd) {
>   Gtk.Application.Invoke (delegate {
>       TextIter mIter = txvMonitor.Buffer.EndIter;
>       txvMonitor.Buffer.Insert(ref mIter, sToAdd);
>       txvMonitor.ScrollToIter(txvMonitor.Buffer.EndIter, 0, false, 0, 0);
>       });
> }
>
> the problem seems solved ... Thank you Michael!!!

Yes, async callbacks are usually called from threadpool threads, so
your solution is correct.

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Monodevelop-list mailing list