I have written a windows service code in C#.NET containing 2 threads running simultaneously which is working as per expected.
Now, I copied the same project to different location, built the solution and copied the service to the destination VM machine (Windows 7). But one of the threads stuck up at a function call i.e. once the execution reaches the function call, it gets stuck up and this thread just wont respond.. no exception nothing. Now, try to stop this service, it will take huge time, wont stop sometimes and will leave a stray process in the task manager which will be vanished after few minutes.
Same thing happened when I copied the solution to some another location.
Now, again, I use my original location, copy this service to destination VM machine and voila.. everything is working perfectly.
We tried calling some other function from the same class, it is getting called. But not the one which we want to.
And this happens only on my laptop. On my colleagues laptop, it works fine.
Anybody came across this issue??
Please help.
The code is as below -
The calling function is a normal function from a class.
The function which is getting called is inside a class which is as follows -
class A {
// Some variables
public A(parameter a) // constructor
{ }
void function1(object A)
{ }
bool function2(B b) // this is the calling class
{
Log("some message"); // this is 1st line of the function.
... ...
}
}
calling code is -
A a = new A(param);
a.function1(obj); // Works
a.function2(this); // stuck up at this call.. do not even print log message which is at the entry point. even if we change or remove parameter altogether.. just have some issue with function
Just reinstalling Visual Studio worked for me.
Thanks!
Related
So I have a problem with the xmldocument.load function MSND Link . Specifically, it runs fine in the code but upon closing the program it causes an error in ntdll.dll.
Picture of Error
However, if I remove this function from the program I’m writing and run it separately it works without error. Also if I run the rest of my program with some dummy input it runs and closes without error as well.
To be clear this is running as a windows forms application with these functions being called from a google API library I’m putting together.
public static string Test()
{
XmlDocument XML = new XmlDocument();
XML.Load(#"https://maps.googleapis.com/maps/api/distancematrix/xml?units=imperial&origins=Vancouver+BC|Seattle&destinations=San+Francisco|Vancouver+BC&key=AIzaSyA_j0g3zKKhosZz9uEXwCWd2fuv3WCwHPk");
string S = XML.ChildNodes[1].ChildNodes[3].ChildNodes[0].ChildNodes[0].InnerText;
return S;
}
How would I Resolve this error message?
Sense it dose not appear to be causing issues with the program I would also accept a way to suppress the error message from popping up after the program closes. Though obviously I would prefer to fix the issue than just cover it up.
Edit: 4/18/2016
I just made one of my first Alpha testing builds of the program and when the program is being run from outside of Visual studio after using WIX to create an installer and install it it is not throwing the error. still acting up from within visual studio though very odd.
I have a c# console application.
The program is very simple. It simply opens a Matlab application & specifies the directory of the m-file I wish to run, supplying one parameter (code is below). The code in the m-file basically uploads some data to a datbase. After this an excel report is created from the data uploaded to the database.
I have this task scheduled to run at 4am. The code worked fine for the first two months. However (without any changes I'm aware of) the code is not working. I come in the morning to see that it has opened an instance of matlab & it has changed the matlab directory but it does not appeared to have run the matlab function. Its strange as the c# code then runs the excel code afterwards which reprots there is no data in the database. When I come in and run the code manually though the code works fine. I don't know what is happening or how to find out what is going on?
In windows scheduled the task has the message "the operation completed successfully. (0x0)
public void CalculateFundDrift()
{
try
{
// create matlab instance
_matlab = new MLApp.MLApp();
// change to the directory where the function is located
_matlab.Execute(#"cd c:\my_directory\");
// define the output
object result = null;
// call the matlab function upload_data
_matlab.Feval("my_func_name", 0, out result, "my_para");
// quit matlab
Console.WriteLine(Environment.NewLine + "Closing Matlab");
_matlab.Quit();
}
catch(Exception ex)
{
_matlab.Quit();
throw;
}
}
Update
One thing I do no notice when running the code is that it opens a matlab command window (looks more like a text file). In the morning when I come in its an actual matlab application that has been left open.
I have a C# application that loads fine on my development machine but fails to even start on Win2008 machine.
Checked Frameworks and they match up, Net 4.0
I immediately suspected the problem was arising from references to specific files that I was reading from and sure enough, using some test code I narrowed it down to a single line.
public static string[] salesArray = (File.ReadAllLines("sales.txt").ToArray());
If I comment out the above line, the test app starts, if I leave it in, it fails. Any ideas?
I am copying the Debug directory to the second machine (sales.txt) within it.
This is the entire code. The app does nothing but open a blank window.
namespace testServer
{
public partial class Form1 : Form
{
public static string[] salesArray = (File.ReadAllLines("sales.txt").ToArray());
public Form1()
{
InitializeComponent();
}
}
}
Two potential issues jump out:
1) The current working directory of the app isn't what you think it is:
If you can print/show this, you would know for sure.
http://msdn.microsoft.com/en-us/library/system.io.directory.getcurrentdirectory.aspx
Because you are specifying a relative path, the current working directory is what the file is being resolved against.
2) Perhaps permissions. You might right-click, 'Run as administrator' as a quick check into that theory.
You should use a better mechanism to find that file, and check for its existence (ie: File.Exists) prior to opening it.
This will also let you report to the user if there is a problem, such as the file not existing where you expect it to be.
Put an exception handler around the code. You can get the error message and can handle the failure gracefully.
It should handle all errors (file not found, file in use, permission errors, etc.).
I'm a Silverlight/ASP.NET developer trying to write my first Windows Forms application to run in the background on a server, populating our database. Eventually would like this to be a Windows service, but it's not required initially.
I need to create a batch file to execute 5 instances of this application, passing in the URL to 5 RESTful endpoints. So I published my app, which created a setup.exe. After installing it, I have an item that points to
C:\Users\mi2dev\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Microsoft\, with a .appref-ms file.
I'm not sure at this point what to do. Running:
"C:\Users\mi2dev\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Microsoft\StreamingApp.appref-ms" -"http://www.myURL.com" throws up a command window briefly, but the app doesn't run, data doesn't populate in DB.
What am I missing here?
since your application is in .exe format. And make your winform accepts command line arguments (check the main method) also make your Form ctor accepts params too. Then just launch it via cmd line just as you would other command, but here only to navigate to that dir where file exists.
In case of batch, use start command followed by program name and then arguments
It's hard to understand what is happening inside your application. You need to debug to understand what is going on there when it receives given parameters.
So I would suggest to debug an EXE. For this go to your EXE project properties, select DEBUG tab in CommandLineArguments insert your parameter string.
Run it in DEBUG and hopefully you will figure out a problem.
If after debugging it's not yet clear why it behaves in that way, come back to SO :)
Silvi if you plan to use your windows forms application from a batch file and you imagine the applicationm will behave differently in such mode than when opened witha double click, the usual approach is to parse the command line (arguments, also available in the main method as parameter) and to avoid loading the UI at all.
in fact if you have written your application properly the UI only managed the UI and does not contain the whole logic of database manipulation and data transformation.
what you could do is check inside the Main method if there are command line parameters and if you detect any of the special ones you have definded you really avoid to even call Application.Run(new Form1(...)); and start working in batch mode without user interface.
the same logic you want to use in batch mode or in UI mode can be wrapped in helper classes (often also called business managers or business logic... it depends), so that you do not have code duplication but simply UI or batch will call those classes nicely.
I am trying to use R(D)Com interface. I have R 2.12.1 installed on machine. For using this interface in C#, I loaded rscproxy_1.3-1 package and then installed R_Scilab_DCOM3.0-1B5 on my machine. Also, I copied sciproxy.dll from Program Files\R(D)COM Server\Scilab to Program Files\R(D)COM Server\bin, as informed while installing the interface.
My Problem:
As a part of testing, I tried the code from blog post http://vvella.blogspot.com/2010/08/integrate-c-net-and-r-taking-best-of.html. But my form application failed due to exception raised by statement rconn.Init(“R”). The exception text was Exception from HRESULT: 0x80040013 I tried to run samples from Programs->R->R(D)COM Server->Server 01 Basic Test. On launched form, I clicked button “Start R” but it failed with error printed in text box as “Initializing R...Function call failed Code: -2147221485 Text: installation problem: unable to load connector”
I tried this:
I tried to troubleshoot it with the help of Index html page, and there under installation section, I found that there must be rproxy.dll under installed R/Bin folder. Also, HKEY_LOCAL_MACHINE\Software\R-core\R\InstallPath should point to installation folder.
Things lacking on my machine are
the installed R/bin folder doesn’t
contain rproxy.dll. Where can I get
this dll? Or is it sciproxy.dll
instead?
HKEY_LOCAL_MACHINE\Software\R-core\R\InstallPath
points to installation folder, but
there is no entry under
HKEY_CURRENT_USER\Software.
I can guess there is something fishy about installation, or registering COM server. But I am not successful in figuring it out.
Could you please tell me where am I going wrong?
thanks,
Kapil
Oh god I remember this being a huge pain in the arse. Lets see if I can remember... And before I start, I warn you that I just "got this working" and never cared to work out if I could remove parts from the process.
Downloads are available from http://rcom.univie.ac.at/download.html . If I remember correctly, the RandFriends package is all you need, it installs a crapload (just install it all) but is simple. Alternatively, I think if you install the 'rscproxy' package in R you can just download the 'statconnDCOM' and install that. Memory is hazy, but I know one of these methods results in an annoying splash screen everytime you run your C# executable, and one doesn't. Although that could have just been some setting I played with.
Now, I can't remember how you verify that stuff has installed successfully. Pretty sure it comes with examples though. Once that is started, get your C# project open. Reference the following projects,
StatConnectorCommonLib
STATCONNECTORSRVLib
In your code, you will probably want to implement a IStatConnectorCharacterDevice so you get the R output coming back out in C#. Your code to initialise will then look something like,
private StatConnector _StatConn;
private IStatConnectorCharacterDevice _CharDevice;
private Whatever()
{
// declare
_StatConn = new StatConnectorClass();
_CharDevice = new MyCharDevice();
// init R, wire up char device
_StatConn.Init("R");
_StatConn.SetCharacterOutputDevice(_CharDevice);
}
Then you should be able to just use the functions as needed
_StatConn.EvaluateNoReturn("x <- 3");
var returnObj = _StatConn.Evalute("1 + 1");
Hope that helps.
tl;dr download RAndFriends, do fresh install with that
I had a similar problem calling R.Init(), I found R.GetErrorText() returns the actual error message