Hello, all.
I'm developing an application that has a listview of records
(pulled from the database) and a preview pane. Basically, when the
user clicks on a record in the listview the preview pane gets
populated with additional information about the record. Each record
also have a variable number of pictures. What I want to do is have
the application fetch the pictures from the database in a separate
thread. What is the best way to do this? I tried creating a Thread
object every time and invoke a method, however If I scroll really
fast in the listview the application crashes and I cannot debug it. Is
there a specific section that I should lock() when the thread is
started? Also how do i guarantee that the last record selected is that
one that will have the most recent started thread's data?
Thanks, 3 9067
It sounds to me that most likely your issue revolves around attempting to
update a control on the UI (main) thread from another thread. You need to use
a delegate to do this.
Here is a nice little reusable pattern that you can look at:
delegate void SetValueDelegate(Object obj, Object val, Object[] index);
public void SetControlProperty(Control ctrl, String propName, Object val)
{
PropertyInfo propInfo = ctrl.GetType().GetProperty(propName);
Delegate dgtSetValue = new SetValueDelegate(propInfo.SetValue);
ctrl.Invoke(dgtSetValue, new Object[3] { ctrl, val, /*index*/ null });
}
// Usage: SetControlProperty(label1, "Text", myString);
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Ludwig Wittgenstein" wrote:
Hello, all.
I'm developing an application that has a listview of records
(pulled from the database) and a preview pane. Basically, when the
user clicks on a record in the listview the preview pane gets
populated with additional information about the record. Each record
also have a variable number of pictures. What I want to do is have
the application fetch the pictures from the database in a separate
thread. What is the best way to do this? I tried creating a Thread
object every time and invoke a method, however If I scroll really
fast in the listview the application crashes and I cannot debug it. Is
there a specific section that I should lock() when the thread is
started? Also how do i guarantee that the last record selected is that
one that will have the most recent started thread's data?
Thanks,
to avoid useless call to the database when scrolling in the ListView,
you should use a Delayed event handling mechanism : http://www.vbinfozine.com/a_deh.shtml
Didier
"Ludwig Wittgenstein" <se********@hotmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
Hello, all.
I'm developing an application that has a listview of records
(pulled from the database) and a preview pane. Basically, when the
user clicks on a record in the listview the preview pane gets
populated with additional information about the record. Each record
also have a variable number of pictures. What I want to do is have
the application fetch the pictures from the database in a separate
thread. What is the best way to do this? I tried creating a Thread
object every time and invoke a method, however If I scroll really
fast in the listview the application crashes and I cannot debug it. Is
there a specific section that I should lock() when the thread is
started? Also how do i guarantee that the last record selected is that
one that will have the most recent started thread's data?
Thanks,
On 19 jun, 13:44, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
It sounds to me that most likely your issue revolves around attempting to
update a control on the UI (main) thread from another thread. You need to use
a delegate to do this.
Here is a nice little reusable pattern that you can look at:
delegate void SetValueDelegate(Object obj, Object val, Object[] index);
public void SetControlProperty(Control ctrl, String propName, Object val)
{
PropertyInfo propInfo = ctrl.GetType().GetProperty(propName);
Delegate dgtSetValue = new SetValueDelegate(propInfo.SetValue);
ctrl.Invoke(dgtSetValue, new Object[3] { ctrl, val, /*index*/ null });
}
// Usage: SetControlProperty(label1, "Text", myString);
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Ludwig Wittgenstein" wrote:
Hello, all.
I'm developing an application that has a listview of records
(pulled from the database) and a preview pane. Basically, when the
user clicks on a record in the listview the preview pane gets
populated with additional information about the record. Each record
also have a variable number of pictures. What I want to do is have
the application fetch the pictures from the database in a separate
thread. What is the best way to do this? I tried creating a Thread
object every time andinvokea method, however If I scroll really
fast in the listview the application crashes and I cannot debug it. Is
there a specific section that I should lock() when the thread is
started? Also how do i guarantee that the last record selected is that
one that will have the most recent started thread's data?
Thanks,- Tekst uit oorspronkelijk bericht niet weergeven -
- Tekst uit oorspronkelijk bericht weergeven -
If you can, it's better to use BeginInvoke() instead of Invoke().
Read more about it (and other threading issues) here: http://kristofverbiest.blogspot.com/...gininvoke.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mihai |
last post by:
What does the standard say about those two? Is any assurance that the
use of STL is thread safe?
Have a nice day,
Mihai.
|
by: J.Marsch |
last post by:
I know that the controls on a Winform are not thread safe, and that you want
to do all of your UI updates on a single thread -- generally the main
thread.
Now, 2 questions:
1. Does the one...
|
by: Robert Zurer |
last post by:
Can anyone suggest the best book or part of a book on this subject. I'm
looking for an in-depth treatment with examples in C#
TIA
Robert Zurer
robert@zurer.com
|
by: sarge |
last post by:
I would like to know how to perform simple multithreading.
I had created a simple form to test out if I was multithreading
properly, but got buggy results. Sometime the whole thig would lock
up...
|
by: tommy |
last post by:
hi,
i have found a example for multithreading and asp.net
http://www.fawcette.com/vsm/2002_11/magazine/features/chester/
i want to speed up my website ...
if my website is starting, they...
|
by: Rich |
last post by:
Hello,
I have set up a multithreading routine in a Test VB.net
proj, and it appears to be working OK in debug mode and I
am not using synchronization. Multithreading is a new
thing for me, and...
|
by: sandy82 |
last post by:
Whats actuallly multithreading is ... and how threading and
multithreading differ .
Can any1 guide how multithreading is used on the Web .. i mean a
practical scenario in which u use...
|
by: brian.wilson4 |
last post by:
Our group is currently comparing winforms vs webforms.....app is Corp
LAN based - we have control of desktops.....Below is pros and cons list
we have come up with - if anything strikes you as...
|
by: Ray |
last post by:
Hello,
Greetings! I'm looking for a solid C++ multithreading book. Can you
recommend one? I don't think I've seen a multithreading C++ book that
everybody thinks is good (like Effective C++ or...
|
by: =?Utf-8?B?TWljaGFlbCBXLg==?= |
last post by:
Dear ng,
i have developed a winforms application with vs2005.
An progress from with a animation and a timer is shown while the
application is working.
The trouble is, that often a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |