A
Asheesh
Hi All,
I'm using 2 listview controls in a form. Both listview controls contain
items. The items in both listview controls have 1-1 mapping with each other.
E.g. Item 1 is listView control 1 is related to item 2 in listView control
2.
Now I've associated a single click with the Item_Activate event of the
listView control. So, that when Item 1 of listView control 1 is clicked, the
corresponding item 1 in the listView control is highlighted.
For this I'm using listView.EnsureVisible method in source listview control
to highlight the corresponding item in the target listview control.
E.g
private void lvSource_ItemActivate(object sender, System.EventArgs e)
{
int i=lvSource.SelectedIndices[0];
lvTarget.Items.Selected = true;
lvTarget.EnsureVisible(i);
//Plays the audio mp3 for the clicked item.
Player.PlayAudioFile(Convert.ToInt32(lvSource.Items.SubItems[1].Text),"So
urce");
}
All this works fine.. Now when a particular item is clicked on listview
control, I also play that particular item audio file, which is MP3 by using
an audio engine.
For this I PInvoke the particular function and then use it's PlayAudioFile
function listed above to play the audio file.
All this is fine, but when I play the audio file, the audio file plays
first and then the corresponding item in the target listview is highlighted.
Since it occurs in the main thread, there is a delay since first the audio
files playbacks and then the item is highlighted.
For this I'm thinking of playing in a separate thread, but I'm confused as
to should I start a new thread everytime, when the user clicks the item and
execute the playAudioFile method or use the ThreadPool class to execute my
method by virtue of threads being maintained by it.
Are there any performance benefits associated with ThreadPool class?
Moreover, I have a fear, since ThreadPool class can generate multiple
threads for execution, there might be a case, where a user might click on a
particular item while the audio playback of first item is still in progress.
This way, a memory exception might occur, since the second thread would try
to create the audio object in my dll and try to play the audio file, while a
previous audio file is still in progress.
Is there a way to avoid this possible conflict by making use of a ThreadPool
or even spawning a new thread?
Please help,
Any help would be greatly appreciated.
Regards,
Asheesh
I'm using 2 listview controls in a form. Both listview controls contain
items. The items in both listview controls have 1-1 mapping with each other.
E.g. Item 1 is listView control 1 is related to item 2 in listView control
2.
Now I've associated a single click with the Item_Activate event of the
listView control. So, that when Item 1 of listView control 1 is clicked, the
corresponding item 1 in the listView control is highlighted.
For this I'm using listView.EnsureVisible method in source listview control
to highlight the corresponding item in the target listview control.
E.g
private void lvSource_ItemActivate(object sender, System.EventArgs e)
{
int i=lvSource.SelectedIndices[0];
lvTarget.Items.Selected = true;
lvTarget.EnsureVisible(i);
//Plays the audio mp3 for the clicked item.
Player.PlayAudioFile(Convert.ToInt32(lvSource.Items.SubItems[1].Text),"So
urce");
}
All this works fine.. Now when a particular item is clicked on listview
control, I also play that particular item audio file, which is MP3 by using
an audio engine.
For this I PInvoke the particular function and then use it's PlayAudioFile
function listed above to play the audio file.
All this is fine, but when I play the audio file, the audio file plays
first and then the corresponding item in the target listview is highlighted.
Since it occurs in the main thread, there is a delay since first the audio
files playbacks and then the item is highlighted.
For this I'm thinking of playing in a separate thread, but I'm confused as
to should I start a new thread everytime, when the user clicks the item and
execute the playAudioFile method or use the ThreadPool class to execute my
method by virtue of threads being maintained by it.
Are there any performance benefits associated with ThreadPool class?
Moreover, I have a fear, since ThreadPool class can generate multiple
threads for execution, there might be a case, where a user might click on a
particular item while the audio playback of first item is still in progress.
This way, a memory exception might occur, since the second thread would try
to create the audio object in my dll and try to play the audio file, while a
previous audio file is still in progress.
Is there a way to avoid this possible conflict by making use of a ThreadPool
or even spawning a new thread?
Please help,
Any help would be greatly appreciated.
Regards,
Asheesh