如何在不返回任何值的情况下停止控制器

时间:2013-12-06 11:48:08

标签: c#

public int BackgroundService(string lati, string longi) {
        BackGroundService objBGServices = new BackGroundService();
        return objBGServices.DispatcherTimerSetup(httpClient, lati, longi, UserId);
}

但我得到的错误就像

  

错误:   错误83无法将类型'void'隐式转换为'int'

2 个答案:

答案 0 :(得分:4)

假设DispatcherTimerSetup返回void:

public void BackgroundService(string lati, string longi) {
        BackGroundService objBGServices = new BackGroundService();
        objBGServices.DispatcherTimerSetup(httpClient, lati, longi, UserId);
}

删除int的返回值并且不返回任何内容:只需执行操作。

答案 1 :(得分:0)

将其函数返回类型设为Void。并且不要退货

基于您的函数返回类型:

DispatcherTimerSetup返回void,这意味着什么。在BackgroundService函数中返回int值的位置。这就是你得到的原因

  

错误83无法将类型'void'隐式转换为'int'

public void DispatcherTimerSetup(HttpClient httpClient, string lati, string longi, string UserId) 
{ 
     dispatcherTimer = new DispatcherTimer(); 
     dispatcherTimer.Tick += dispatcherTimer_Tick; 
     dispatcherTimer.Interval = new TimeSpan(0, 0, 1); 
     // TimeSpan for 1 Minute 0 secs 
     if (!dispatcherTimer.IsEnabled) 
     { 
          dispatcherTimer.Start(); 
     }
}

//Wrong return Type
public int BackgroundService(string lati, string longi) {
    BackGroundService objBGServices = new BackGroundService();
    //Problem is Return Type
    return objBGServices.DispatcherTimerSetup(httpClient, lati, longi, UserId);
}

//See the Answer of **Jeroen Vannevel**

public void BackgroundService(string lati, string longi) {
    BackGroundService objBGServices = new BackGroundService();
    objBGServices.DispatcherTimerSetup(httpClient, lati, longi, UserId);
}