Hello, I have a WCF Web Service, that makes a SQL query to a data base and returns a DataSet with the data.
In my WPF browser app I have a gridView and it's ItemsSource is the DataSet that the service returns, at first I got this code:
It works fine, and does what it's supposed to do, the call to the service takes some moments, so I decided to change the cursor to a clock, but once I had it all working I like to change it for a busy indicator, so I added it to my code:
a
It's the same code, and it should work, but when I try to call the service:
I get an exception:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in Unknown Module.
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
If I remove the busy indicator and the background worker it works fine and I can't understand what's happening, I have no clue,
I hope somebody can help me.
Thanks!!
In my WPF browser app I have a gridView and it's ItemsSource is the DataSet that the service returns, at first I got this code:
if
(grid.ItemsSource ==
null
)
{
//Creates the reference for the duplex Service
InstanceContext instanceContext =
new
InstanceContext(
new
CallbackHandler());
ServiceReference1.ServiceDuplexClient client2 =
new
ServiceDuplexClient(instanceContext);
this
.Cursor = System.Windows.Input.Cursors.Wait;
//Call the service functon that returns the DataSet
DataSet ds = client2.EventSummary();
this
.Cursor = System.Windows.Input.Cursors.Arrow;
if
(ds !=
null
)
{
if
(ds.DataSetName.Equals(
"OK"
))
{
//If it's OK the DataSet is the ItemsSource of the grid
grid.ItemsSource = ds;
}
}
}
It works fine, and does what it's supposed to do, the call to the service takes some moments, so I decided to change the cursor to a clock, but once I had it all working I like to change it for a busy indicator, so I added it to my code:
<
telerik:RadBusyIndicator
x:Name
=
"busyIndicator"
BusyContent
=
"Loading data...."
Grid.ColumnSpan
=
"3"
Grid.RowSpan
=
"3"
>
a
public
partial
class
Page1 : Page
{
//Declare my background worker
BackgroundWorker workerOperAct =
new
BackgroundWorker();
public
Page1()
{
InitializeComponent();
workerOperAct.DoWork +=
this
.WorkerOperActDoWork;
workerOperAct.RunWorkerCompleted += WorkerOperActRunWorkerCompleted;
}
private
void
WorkerOperActDoWork(
object
sender, DoWorkEventArgs e)
{
//Create the reference for the service
InstanceContext instanceContext =
new
InstanceContext(
new
CallbackHandler());
ServiceReference1.ServiceDuplexClient client2 =
new
ServiceDuplexClient(instanceContext);
//Call the service function that returns the DataSet
DataSet ds = client2.EventSummary();
if
(ds !=
null
)
{
if
(ds.DataSetName.Equals(
"OK"
))
{
grid.ItemsSource = ds;
}
}
}
void
WorkerOperActRunWorkerCompleted(
object
sender, RunWorkerCompletedEventArgs e)
{
grid.Visibility = Visibility.Visible;
this.busyIndicator.IsBusy = false;
}
//More code....
}
It's the same code, and it should work, but when I try to call the service:
DataSet ds = client2.EventSummary();
I get an exception:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in Unknown Module.
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
If I remove the busy indicator and the background worker it works fine and I can't understand what's happening, I have no clue,
I hope somebody can help me.
Thanks!!