error 1053: the service did not respond to the start or control request in a timely fashion on visual studio 2015 - service

I made a windows service using C# as follow
public partial class Housekeeping : ServiceBase
{
#region Fields
private ManualResetEvent _ResetEvent = new ManualResetEvent(false);
private RegisteredWaitHandle _RegisteredWaitHandle;
private long _Interval = 60000;
private Logger _Logger;
#endregion
#region Constructors
public Housekeeping()
{
InitializeComponent();
_Interval = _Interval * Convert.ToInt32(ConfigurationManager.AppSettings["RunningInterval"]);
_Logger = new Logger();
}
#endregion
#region Properties
#endregion
#region Behaviors
public void Housekeep(object state, bool timeout)
{
try
{
// my code
}
catch (Exception ex)
{
// my code
}
}
protected override void OnStart(string[] args)
{
_RegisteredWaitHandle = ThreadPool.RegisterWaitForSingleObject(_ResetEvent, new WaitOrTimerCallback(Housekeep), null, _Interval, false);
}
protected override void OnStop()
{
}
protected override void OnContinue()
{
base.OnContinue();
}
protected override void OnPause()
{
base.OnPause();;
}
}
and on the main
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Housekeeping()
};
ServiceBase.Run(ServicesToRun);
}
}
I Installed the WS using InstallUtil.exe, but when I tried to start the WS I got this error "error 1053: the service did not respond to the start or control request in a timely fashion". I surfed around but all the solution are for a windows server 2003 issue and I'm running Windows 10.
How can I solve this issue?

Last time I have seen this issue, it got resolved by changing the compiling option from 'Debug' to 'Release'.

Related

How to use log4net in MAUI

MAUI is a new platform. I used log4net with worker service but doesn't know how to use with MAUI.
Can you supply full sample code how to use log4net with MAUI ?
Thanks in advance.
public class AppLogManager {
private static AppLogManager _logManager = null;
public ILog _logger;
private AppLogManager()
{ }
public AppLogManager(string fullConfigFilePath, Assembly assembly)
{
var logRepo = log4net.LogManager.GetRepository(assembly); log4net.Config.XmlConfigurator.Configure(logRepo, new FileInfo(fullConfigFilePath)); _logManager = new AppLogManager();
}
public static AppLogManager GetLogger<T>()
{
return _logManager.GetLogger(typeof(T));
}
public AppLogManager GetLogger(Type type)
{
_logger = log4net.LogManager.GetLogger(type);
return _logManager;
}
public void Info(string message)
{
_logger.Info(message);
}

Handling CuratorFramework close method properly

I'm receiving a stack trace in log files when testing my ZooKeeperFetcher class. I'm quite sure that the problem lies in the fact
that CuratorFramework client is being closed before the pathChildrenCache instance. Is it possible for pathChildrenCache to detect and
call close() once curatorFramework was closed? I cannot simply add new close() -> {pathChildrenCache.close(); } method to ZooKeeperFetcher.
Simplified code:
public class ZooKeeperFetcher() {
private final CuratorFramework client;
private PathChildrenCache pathChildrenCache;
ZooKeeperFetcher(CuratorFramework client) {
this.client = client;
pathChildrenCache = new PathChildrenCache(client, '/', true);
PathChildrenCacheListener pathListener =
(client, event) -> /* handle event */;
}
/* this option is just not possible for me */
// public void close() {
// pathChildrenCache.close();
// }
}
And the test class:
public class TestZooKeeperFetcher {
private TestingServer zookeeperServer;
private final CuratorFramework client;
private ZooKeeperFetcher fetcher;
#Before
public void beforeEachTest() {
zookeeperServer = new TestingServer(true);
client =
CuratorFrameworkFactory.newClient(
zookeeperServer.getConnectString(), new RetryNTimes(10, 50));
client.start();
fetcher = ZooKeeperFetcher(client);
}
#After
public void afterEachTest() throws Exception {
client.close();
}
#Test
public void justDontThrowExceptionsTest() throws Exception {
}
}

scriptcs Mixed mode assembly error

I have added an application in scriptcs and added some references to assemblies which have the version v2.0.50727. So while running the scriptcs file it returns as Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime.Setting attribute useLegacyV2RuntimeActivationPolicy="true" in app.config may resolve the issue in asp.net web application. but in scriptcs its not working. further searching reveals that above attribbute useLegacyV2RuntimeActivationPolicy="true" should be added as scriptcs.exe.config. I have an application file named FMUpgrade.csx and how can we reference this scriptcs.exe.config in the FMUpgrade.csx file.scriptcs docs doesn't say much about scriptcs.exe.config.Also added program.exe.config with app.config but still not success.
After much research I got a workaround solution to the above problem.
By make use of class ExeConfigurationFileMap we could able to get the key values from app.config, its not able to bypass the supported runtime error caused by mixed mode assembly error.
Server server = new Server(new ServerConnection(con)); server.ConnectionContext.ExecuteNonQuery(script);
The error is caused while executing the statement ExecuteNonQuery.
So before executing the statement
if( RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully )
server.ConnectionContext.ExecuteNonQuery(script);
Solution is below
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public static class RuntimePolicyHelper
{
public static bool LegacyV2RuntimeEnabledSuccessfully
{ get; private set; }
static RuntimePolicyHelper()
{
ICLRRuntimeInfo clrRuntimeInfo =
(ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(
Guid.Empty,
typeof(ICLRRuntimeInfo).GUID);
try
{
clrRuntimeInfo.BindAsLegacyV2Runtime();
LegacyV2RuntimeEnabledSuccessfully = true;
}
catch (COMException)
{
// This occurs with an HRESULT meaning
// "A different runtime was already bound to the legacy CLR version 2 activation policy."
LegacyV2RuntimeEnabledSuccessfully = false;
}
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("BD39D1D2-BA2F-486A-89B0-B4B0CB466891")]
private interface ICLRRuntimeInfo
{
void xGetVersionString();
void xGetRuntimeDirectory();
void xIsLoaded();
void xIsLoadable();
void xLoadErrorString();
void xLoadLibrary();
void xGetProcAddress();
void xGetInterface();
void xSetDefaultStartupFlags();
void xGetDefaultStartupFlags();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void BindAsLegacyV2Runtime();
}
} using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public static class RuntimePolicyHelper
{
public static bool LegacyV2RuntimeEnabledSuccessfully { get; private set; }
static RuntimePolicyHelper()
{
ICLRRuntimeInfo clrRuntimeInfo =
(ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(
Guid.Empty,
typeof(ICLRRuntimeInfo).GUID);
try
{
clrRuntimeInfo.BindAsLegacyV2Runtime();
LegacyV2RuntimeEnabledSuccessfully = true;
}
catch (COMException)
{
// This occurs with an HRESULT meaning
// "A different runtime was already bound to the legacy CLR version 2 activation policy."
LegacyV2RuntimeEnabledSuccessfully = false;
}
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("BD39D1D2-BA2F-486A-89B0-B4B0CB466891")]
private interface ICLRRuntimeInfo
{
void xGetVersionString();
void xGetRuntimeDirectory();
void xIsLoaded();
void xIsLoadable();
void xLoadErrorString();
void xLoadLibrary();
void xGetProcAddress();
void xGetInterface();
void xSetDefaultStartupFlags();
void xGetDefaultStartupFlags();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void BindAsLegacyV2Runtime();
}
}

Setting fetch size in entity framework

I am converting ado.net code to use EF. In my ado.net code i set dataReader.FetchSize = command.RowSize * 1000 and that dramatically improves performance over the default fetch size .
When I convert my code to EF, the performance is on par to ado.net code where I didn't specify fetch size, i.e. it's very slow over large records.
Any way I could specify fetch size for retrieving records in EF?
You can set ODP.NET FetchSize in the Registry or the .NET config files when using Entity Framework. That will standardize the FetchSize across all your ODP.NET instances (in the case of the Registry) or across your application (in the case of app/web.config).
http://docs.oracle.com/cd/E48297_01/doc/win.121/e41125/featConfig.htm
Christian Shay
Oracle
I was running into a similar problem, but don't want to change the overall FetchSize, instead I want to change the FetchSize per query.
Here is the solution I came up with, maybe this helps someone.
It basically uses the CallContext to pass arguments to a DbInterceptor. The interceptor will override the needed properties on the query commands.
Thread safe with support for nesting scopes.
This can be as well used to modify other properties of commands executed through Entity Framework queries for a defined scope.
Usage:
using (var context = new MyDbContext())
{
using (new OracleCommandContext(fetchSize: 1024 * 128))
{
// your query here
}
}
Properties to override:
public class OracleCommandProperties
{
public long FetchSize { get; set; } = 524288; // oracle default value
}
The call context:
public class OracleCommandContext : IDisposable
{
private static readonly object sync = new object();
private readonly OracleCommandProperties previousCommandProperties;
private bool isDisposed;
static OracleCommandContext()
{
DbInterception.Add(new OracleCommandInterceptor());
}
public OracleCommandContext(long fetchSize)
{
lock (sync)
{
var commandProperties = new OracleCommandProperties();
if (TryGetProperties(out var previousProperties))
{
// when using nested OracleCommandContext, escalate the properties
previousCommandProperties = previousProperties;
commandProperties.FetchSize = Math.Max(previousProperties.FetchSize, fetchSize);
}
else
{
commandProperties.FetchSize = fetchSize;
}
CallContext.LogicalSetData(nameof(OracleCommandProperties), commandProperties);
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~OracleCommandContext()
{
Dispose(false);
}
private void Dispose(bool disposing)
{
if (disposing)
{
if (!isDisposed)
{
lock (sync)
{
CallContext.LogicalSetData(nameof(OracleCommandProperties), previousCommandProperties);
}
isDisposed = true;
}
}
}
public static bool TryGetProperties(out OracleCommandProperties properties)
{
lock(sync)
{
if (CallContext.LogicalGetData(nameof(OracleCommandProperties)) is OracleCommandProperties oracleReaderProperties)
{
properties = oracleReaderProperties;
return true;
}
properties = null;
return false;
}
}
}
The interceptor doing the actual work:
public class OracleCommandInterceptor : IDbCommandInterceptor
{
public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
}
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
AdjustCommand(command);
}
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
}
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
AdjustCommand(command);
}
public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
}
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
AdjustCommand(command);
}
private static void AdjustCommand(DbCommand command)
{
if (command is OracleCommand oracleCommand)
{
if (OracleCommandContext.TryGetProperties(out var properties))
{
oracleCommand.FetchSize = properties.FetchSize;
}
}
}
}

GWT Void remote services fail for seemingly no reason

I'm working on a GWT project and have several void remote services that seem to execute just fine, but on the client side, end up firing the onFailure() method. No exceptions are thrown anywhere, and the expected behavior is observed on the backend. I have no idea what could be going wrong. Here is the relevant code:
Interfaces and implementation...
#RemoteServiceRelativePath("DeleteSearchService")
public interface DeleteSearchService extends RemoteService {
/**
* Utility class for simplifying access to the instance of async service.
*/
public static class Util {
private static DeleteSearchServiceAsync instance;
public static DeleteSearchServiceAsync getInstance(){
if (instance == null) {
instance = GWT.create(DeleteSearchService.class);
}
return instance;
}
}
public void delete(SearchBean search);
}
public interface DeleteSearchServiceAsync {
public void delete(SearchBean bean, AsyncCallback<Void> callback);
}
public class DeleteSearchServiceImpl extends RemoteServiceServlet implements DeleteSearchService {
private static final long serialVersionUID = 1L;
#Override
public void delete(SearchBean search) {
try {
Connection conn = SQLAccess.getConnection();
String sql = "DELETE FROM `searches` WHERE `id`=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, search.getSearchId());
ps.execute();
sql = "DELETE FROM `searchsourcemap` WHERE `search-id` = ?";
ps = conn.prepareStatement(sql);
ps.setInt(1, search.getSearchId());
ps.execute();
return;
} catch (Exception e) {
// TODO Log error
e.printStackTrace();
}
}
}
Calling code...
private class DeleteListener implements ClickListener {
public void onClick(Widget sender) {
DeleteSearchServiceAsync dss = DeleteSearchService.Util.getInstance();
SearchBean bean = buildBeanFromGUI();
dss.delete(bean, new AsyncCallback<Void>(){
//#Override
public void onFailure(Throwable caught) {
// TODO log
SearchNotDeleted snd = new SearchNotDeleted();
snd.show();
}
//#Override
public void onSuccess(Void result) {
SearchDeleted sd = new SearchDeleted();
sd.show();
searchDef.getParent().removeFromParent();
}
});
}
}
I know I'm a jerk for posting like 500 lines of code but I've been staring at this since yesterday and can't figure out where I'm going wrong. Maybe a 2nd set of eyes would help...
Thanks,
brian
LGTM I'm afraid.
Are you using the hosted mode or a full-fledged browser? You can try switching and see if it helps.
Also, it might help listening to that //TODO and perform a GWT.log when onFailure is invoked.