How to populate ListView thread safety in C #?

I need to put some ListView fill code in a stream. For a simple case, this thread should not be started twice. When I want to release a new thread, the previous one should stop, whatever that is.

EDIT 1

The scenario is as follows. I have a text filter over a ListView. In textchange, I call the populateList () method.
The problem is that the code may take longer because it uses SQL syntax LIKEfor a larger database.

Until this is done, the user cannot enter anything. Thus, while you enter “abc”, you can type “outs”, you can enter “c” only after 10 seconds.

Therefore, I mean releasing the populateList () method in Thread and letting the user quickly enter something else. The longer the text, the slower the SQL query. In the “abc” situation, if you type “a”, the code is behind and starts the request, but meanwhile, if the user pressed “b”, I want to stop the execution of the stream “a” and release a new one, now using “ab” ... and so on with c.

EDIT 2

We are looking for more answers.

+3
source share
1 answer

, ... - , , , ... , , ?

Update:
. , db . , db LIMIT, , ,

LIMIT lowerLimit upperLimit

'for' , , . , , , , , .

PSEUDO:

do
  isLoop = false
  clear the collection that is bound to the listbox
  from db, get the record count     
    for: loop 0 to recordcount increment batchsize
      get chuncks of data from db of size batchsize
      add the data to collection [using dispatcher.invoke]
      if textbox text changed
        isLoop = true
        break for-loop
      endif
    endfor
while(isLoop)

, .

+1

Source: https://habr.com/ru/post/1732837/


All Articles