# How to use Hangfire with VB.NET

**URL:** <https://discuss.hangfire.io/t/how-to-use-hangfire-with-vb-net/349>\
**Category:** question\
**Created:** [November 4, 2014, 10:27am UTC](https://discuss.hangfire.io/t/how-to-use-hangfire-with-vb-net/349 "2014-11-04T10:27:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![farid\_masood](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/farid_masood/32/93_2.png) [@farid\_masood](https://discuss.hangfire.io/u/farid_masood)\
**Post date:** [November 4, 2014, 10:27am UTC](https://discuss.hangfire.io/t/how-to-use-hangfire-with-vb-net/349/1 "2014-11-04T10:27:38Z")

</div>

Hello Everyone,

I am able to start the Hangfire with [vb.net](http://vb.net) and here is my code in case if someone needs it

```auto
Imports Hangfire
Imports Hangfire.SqlServer
Imports Microsoft.Owin
Imports Owin

<Assembly: OwinStartup(GetType(Scheduler.Startup))> 

Namespace Scheduler
    ''' <summary>
    ''' Configures the hangfire.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Startup
        Public Sub Configuration(app As IAppBuilder)
            Dim act = Sub(config As IBootstrapperConfiguration)
                          config.UseSqlServerStorage("dbConnection")
                          config.UseServer()
                      End Sub

            app.UseHangfire(act)
        End Sub
    End Class
End Namespace

```

Note in the line

```auto
config.UseSqlServerStorage("dbConnection")

```

I have used the name of my connection string in the web.config file.

---

<div class="post-metadata">

**Author:** ![farid\_masood](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/farid_masood/32/93_2.png) [@farid\_masood](https://discuss.hangfire.io/u/farid_masood)\
**Post date:** [November 7, 2014, 3:34pm UTC](https://discuss.hangfire.io/t/how-to-use-hangfire-with-vb-net/349/3 "2014-11-07T15:34:34Z")

</div>

My aim was to configure the Hangfire in a central Api assembly so that I dont have to add the hangfire to all other assemblies. I am posting my solution here for others who need to do something similar

Blow is the interface and the class I added in the Api assembly

```
    ''' <summary>
    ''' Interface should be implemented by a class if it wants to run
    ''' </summary>
    ''' <remarks></remarks>
    Public Interface IJob

        Sub DoJob()

    End Interface

 Public Class Scheduler

        ''' <summary>
        ''' Adds a background job to be executed. 
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="sJob"></param>
        ''' <remarks></remarks>
        Public Shared Sub AddBackgroundJob(Of T)()
            BackgroundJob.Enqueue(Of T)(Sub(job) CType(job, IJob).DoJob())
        End Sub
End Class

```

Then in one of the other assemblies I did this to add jobs to Hangfire, currently it just contains a method to add a Fire and Forget job.

```
Class StatScheduler
        Implements IJob

        Public Sub DoJob() Implements IJob.DoJob
           ' ToDo
        End Sub
End Class

```

Then finally we send job to the Api form the target assembly like this

```
 Scheduler.AddBackgroundJob(Of StatScheduler)()
```

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [November 10, 2014, 2:37pm UTC](https://discuss.hangfire.io/t/how-to-use-hangfire-with-vb-net/349/4 "2014-11-10T14:37:47Z")

</div>

@farid_masood, thank you for the code snippets that shows how to start Hangfire with [VB.NET](http://VB.NET)! I’ve replaced the first post of this topic to make it easy to find the answer.

---

<div class="post-metadata">

**Author:** ![ChrisQuoDev](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@ChrisQuoDev](https://discuss.hangfire.io/u/ChrisQuoDev)\
**Post date:** [February 12, 2015, 9:21pm UTC](https://discuss.hangfire.io/t/how-to-use-hangfire-with-vb-net/349/5 "2015-02-12T21:21:01Z")

</div>

> [@farid\_masood](#):
>
> \<param name=“sJob”\>\</param\>

Did you intentionally leave out the sJob parameter? Or is it missing in the Sub declaration?
