I have this Code to Get a table Data From SQL Server:
 public  static System.Data.Linq.Table<Equipment> GetEquipmentTable()
        {           
                DataClassesDataContext dc = new DataClassesDataContext();
                return dc.GetTable<Equipment>();            
        }
I Have a Button to call this Function :
  private void button_Click(object sender, RoutedEventArgs e)
    {
       MyListView.DataContext = GetEquipmentTable();
    }
My Problem is :When I Disable Communication Between my App and SQL Server Machine and then click this button, It takes a while to throw an Exception that Connect to Database is impossible!!!! My major problem is that my app freezed till this Exception accrued.
Did I missed something ?
Update 1 :
I used async and wait base on Rahul solution
public static async Task<System.Data.Linq.Table<Equipment>> GetEquipmentTable()
        {           
                DataClassesDataContext dc = new DataClassesDataContext();
                return dc.GetTable<Equipment>();            
        }
 private async void button_Click(object sender, RoutedEventArgs e)
    {
       MyListView.DataContext = await GetEquipmentTable();
    }
but it still wait for this line of code :
return dc.GetTable<Equipment>();
and UI freezes as well.
I think dc.gettable<> is not waitable or somthing else !!??
 
     
     
    