Question: ```
**Unable to Route**
 <!DOCTYPE html>
<html lang="en" ng-app="mymodule">
<head>
<meta charset="UTF-8">
<title>Index</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular-route.js"></script>
<script src="angular-resource.min.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script></head>
<body>
<h1>Routing</h1>
 <a href="#/Course">Course</a>
 <a href="#/Students">Students</a>
 <div ng-view></div>
 </body>

```

**ANGULARJS**

```
var myapp = angular.module("mymodule",["ngRoute"]).config(function($routeprovider){$routeprovider

  .when("/Students",{

      templateUrl:"Students.html",
      controller:"studentcontroller"
  })

  .when("/Course",{

      templateUrl:"Course.html",
      controller:"CourseController"
  })});  
myapp.controller("studentcontroller",["$scope",function($scope){

$scope.message="Hello Welcome to students page";}]);

myapp.controller("CourseController",["$scope",function($scope){
 $scope.alert="Welcome to course page";}])

```

<https://i.stack.imgur.com/nG9rK.png>

\*Iam new to angular and when i trying to route iam unable to do that it throws me an error.Please if any one can fix this problem i would really appriciate that.Thanks \*

Answer: 
If I understood your question correctly, the following algorithm should solve your problem:

* As before, create a BackgroundWorker to do your background work.
* In BackgroundWorker\_DoWork,

	+ create a new thread (let's call it the "third-party thread") to call your third-party library, and then
	+ wait for the third-party thread to finish or the timeout to elapse. (\*)

That way, your UI won't block, since *only the Backgroundworker thread* is waiting, not the main thread.

Now about the interesting part: How do you wait for the third-party thread to finish (the step marked with (\*))?

My suggestion would be to simply use "loop waiting with sleep", i.e. (pseudo-code, you can use the `Stopwatch` class for the timeout):

```
do until (third-party thread has finished or x seconds have elapsed):
    Thread.Sleep for 100ms

if third-party thread has not finished:
    Abort it     // we don't have another choice
else
    Process the result

```

It's not best practice, but it's simple, it gets the job done and you can always replace it with fancy cross-thread-syncronization stuff (which is non-trivial to get right) once you got it all working.
It's useless to create a `Forms.Timer` on a non-gui thread. Don't create it on a separate thread. Why are you `Joining` the threads? The usage of `Join` is to block the current thread until the other thread is finished.

This is untested pseudo code, this is for example purpose.

```
public class Form1: Form1
{
    private int timeoutInMsec = 10000;
    private System.Windows.Forms.Timer _timer;
    private Thread _connectThread;

    public Form1()
    {
        _connectThread = new Thread(Connect);
        _connectThread.Start();

        _timer = new System.Windows.Forms.Timer() { Interval = timeoutInMsec };
        _timer.Tick += (_s, _e) => 
                {
                    _timer.Stop();
                    if (_connectThread.ThreadState == ThreadState.Running)
                        _connectThread.Abort();
                };
        };
    }

    private void Connected()
    {

    }

    private void Aborted()
    {

    }

    private void Connect()
    {
        try
        {
            DoConnect3rdPartyStuff();
            this.Invoke(Connected);
        }
        catch(ThreadAbortException)
        {
            // aborted
            this.Invoke(Aborted);
        }       
    }   
}

```