|
Member 12061647 wrote: below code which I saw in code project Please post your question in the forum at the end of the article so the author can help you.
|
|
|
|
|
I have a Hm-tr module and i want to observe it output in a box
I connect it to my pc and i want observe the data that has been received in my pc. it is important that the program writen with c# but if u have any other idea,tell me.
tnk a lot.
|
|
|
|
|
|
|
Context.InvokeAsynchronousTask(() =>
{
});
I have this code, its not getting called from the unit test project.
|
|
|
|
|
Well, without seeing the code for the unit test project, how do you expect anyone to give you any kind of usable answer?
|
|
|
|
|
Most likely the test finishes before the asynchronous task has a chance to execute.
You'll have to wait in the test for the completion of the asynchronous task. If you don't have a callback method that gets executed on completion you might just have to wait a few moments.
I usually use the ManualResetEvent with the WaitOne Method for such cases.
You can specify a timeout after which the execution should continue even if you don't receive a signal.
|
|
|
|
|
Thanks a lot
|
|
|
|
|
I am using WPF TestBlock control and activating a font which family id is Adolescence using Win32 API AddFontResource. This font is available on various document and also can be easily usable just adding the familyname on html web control. But for WPF TextBox it is not working just passing the family name.
I am using following code snippet.
<TextBlock Grid.Row="0" x:Name="SampleText" Text="{Binding
SampleText}" FontFamily="Adolescence" FontStyle="Normal"
FontSize="20"/>
I cannot put our fonts into windows font directory and also cannot add the directory path in FontFamily parameter and cannot add font into package.
I did googling a lot but could not found any solution. I also very curious to know why WPF is application is not able to detect Font while other application is able to detect the same.
Thanks in advance.
|
|
|
|
|
|
Some apps will "infer" a font based on a "name" and some properties; e.g. "Myriad Pro" and italic weight gives "Myriad Pro Italic", etc.
WPF needs the exact font name.
You should check the names of the fonts in the Control Panel "Fonts" app.
There are fonts (indicated with a little "stack" icon) that when clicked in Control Panel will yield other "sub-fonts" (which names one would use in WPF; besides the font properties).
|
|
|
|
|
<connectionstrings>
<add name="CostAllocationEntities2"
="" connectionstring="Data Source=PC210090\SQLEXPRESS;initial catalog=testdb1;Persist Security Info=True;User ID=sa;Password=password1$" providername="System.Data.SqlClient">
SqlConnection conn;
public SqlConnection openconn()
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString);
try
{
if (conn.State == ConnectionState.Closed)
{<br />
conn.Open();
return conn;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Failed to Connect with Database.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return null;
}
return conn;
}
public void GetBackup(string strDBName)
{
if (string.IsNullOrEmpty(strDBName))
{
MessageBox.Show("Server Name & Database can not be Blank");
return;
}
else
{
string destinationPath = ConfigurationManager.AppSettings.Get("BackupDestinationPath");
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
ServerConnection connection = new ServerConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[strDBName];
Backup bkpDBFull = new Backup();
bkpDBFull.Action = BackupActionType.Database;
bkpDBFull.Database = strDBName;<br />
bkpDBFull.Devices.AddDevice(String.Format("{0}{1}-{2}.bak", destinationPath, strDBName, DateTime.Now.ToString("yyyy-MM-dd")), DeviceType.File);
bkpDBFull.BackupSetName = strDBName + " Backup";
bkpDBFull.BackupSetDescription = strDBName + "- Full Backup";
bkpDBFull.ExpirationDate = DateTime.Today.AddDays(10);<br />
bkpDBFull.Initialize = false;
bkpDBFull.SqlBackup(sqlServer);
MessageBox.Show("Backup Done");
}
}
On this line
Database db = sqlServer.Databases[strDBName];
I get an error:
Not allowed to change the 'ConnectionString' property. The connection's current state is connecting."
-- modified 28-Oct-15 2:27am.
|
|
|
|
|
|
Hello guys/gals,
Since a few months i have rather a real head desturbing issue :/
I have developed a plugin architecture that exists of a Host app and several plugins.
The host app basicly loads all the plugins availible, and allows any plugin to interact with the host, and vice versa.
Everything works fine when it comes to using methods/properties ect...accept for the events...
The events are used to send info to any asigned instance, including the plugins.
Whenever i assign the event inside plugin to recieve info from the host then i get the 'System.Reflection.TargetInvocationException'.
The exception is thrown whenever the host invokes the event that has been assigned from plugin instance.
Though i should mention that the event is used by the plugin AND the host.
They both should be revieving the plugin info...
I know ive used several events in a plugin system before, but that was the other way around.
The host was recieving info from plugin , witch works, just the other way arround seems to be a issue.
The Plugins are loaded by system.reflection as raw data and not as a file...
i did this because the plugins are stored in a custom container, compressed and encrypted.
Here is the manager interface (HOST):
public interface IPluginManager : IPluginBase
{
bool IsLoaded { get; }
Settings AppPreferences { get; }
ILogin Server { get; }
byte[] Signature { get; }
AppInfo[] Plugins { get; }
#region Events
event PluginRequestHandler PluginUpdate;
event PluginRequestHandler PluginInstall;
event PluginRequestHandler PluginRemove;
event PluginInstallHandler PluginsToInstall;
event PluginInstallHandler PluginsToUpdate;
event PluginInstallHandler PluginsToRemove;
event PluginHandler PluginActionChanged;
event PluginsHandler PluginsInstalled;
event PluginsHandler PluginsUpdated;
event PluginsHandler PluginsRemoved;
event EventHandler ManagerLoaded;
event EventHandler ManagerLoading;
event EventHandler ManagerDisposed;
#endregion
#region Methods
void LoadAsync();
void Dispose();
void RemovePluginAsync(AppInfo plugin);
bool RemovePlugin(AppInfo plugin);
void InstallPluginAsync(AppInfo plugin);
bool InstallPlugin(AppInfo plugin);
bool InstallNewPlugins();
void InstallNewPluginsAsync();
void MountPluginAsync(AppInfo info);
void UnmountPluginAsync(AppInfo info);
void EnableApp(AppInfo info);
void DisableApp(AppInfo info);
AppInfo[] GetOnlineApps();
#endregion
}
Here the code from plugin instance that init the Host event.
private void MainForm_Shown(object sender, EventArgs e)
{
if (Host != null && Host.PluginManager != null)
{
SCManager = Host.PluginManager;
SCManager.PluginActionChanged += X_PluginActionChanged;
Server = SCManager.Server;
if (Server == null)
{
var x = SCManager.Plugins.FirstOrDefault(t => t.Type == 1);
if (x != null)
SCManager.MountPluginAsync(x);
}
}
OnWindowShown(this);
}
Here is the Code that triggers the event:
protected virtual void OnPluginActionChanged(AppInfo info,PluginActionType action,Exception error = null,object param = null)
{
PluginHandler handler;
lock (_eventlock)
handler = _PluginActionChanged;
handler?.Invoke(this, info, action, error,param);
}
I really hope someone inhere can point me to the right direction, as i'm totally lost...
Thanks! and sorry for my bad english, let me know please if you guys/gals have any more question.
|
|
|
|
|
A TargetInvocationException occurs when an exception is thrown from a constructor. The stacktrace should show where it is trying to create the object that blows.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
MSDN says "The exception that is thrown by methods invoked through reflection. This class cannot be inherited."
so my take is that the issue occurs exactly at the
?.Invoke call.
What I don't understand is why the original poster doesn't just debug the code, and set the debugger to break on all exceptions - easy peasy.
The Plugins are loaded by system.reflection as raw data and not as a file...
i did this because the plugins are stored in a custom container, compressed and encrypted.
This sounds unnecessarily complicated - but I would first test uncompressing/decrypting them first, then go one step at a time, see when the issue occurs.
Best,
John
|
|
|
|
|
John Torjo wrote: MSDN says ..and so begins my favorite line of argumenting.
Upvoted
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I have a WinForm C# application which works perfet on my laptop but when I installed on on another it';s crashing and not throwing any error. When I checked the Windows EventLog I found below errors but can't understand where is the issue and what IO Fle is missing? Can anyone help please..
Thanks,
Jassim[^]
Log Name: Application
Source: Application Error
Date: 27-Oct-15 11:59:36 AM
Event ID: 1000
Task Category: (100)
Level: Error
Keywords: Classic
User: N/A
Computer: AUDITOR
Description:
Faulting application name: TrueAsset.exe, version: 1.0.0.0, time stamp: 0x561e711d
Faulting module name: KERNELBASE.dll, version: 6.2.9200.16384, time stamp: 0x5010ab2d
Exception code: 0xe0434352
Fault offset: 0x00000000000189cc
Faulting process ID: 0x12e0
Faulting application start time: 0x01d11095ce59ce4c
Faulting application path: C:\Program Files (x86)\TrueAsset\TrueAsset\TrueAsset.exe
Faulting module path: C:\Windows\system32\KERNELBASE.dll
Report ID: 0c124612-7c89-11e5-befb-50b7c3624f32
Faulting package full name:
Faulting package-relative application ID:
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Application Error" />
<EventID Qualifiers="0">1000</EventID>
<Level>2</Level>
<Task>100</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2015-10-27T08:59:36.000000000Z" />
<EventRecordID>66461</EventRecordID>
<Channel>Application</Channel>
<Computer>AUDITOR</Computer>
<Security />
</System>
<EventData>
<Data>TrueAsset.exe</Data>
<Data>1.0.0.0</Data>
<Data>561e711d</Data>
<Data>KERNELBASE.dll</Data>
<Data>6.2.9200.16384</Data>
<Data>5010ab2d</Data>
<Data>e0434352</Data>
<Data>00000000000189cc</Data>
<Data>12e0</Data>
<Data>01d11095ce59ce4c</Data>
<Data>C:\Program Files (x86)\TrueAsset\TrueAsset\TrueAsset.exe</Data>
<Data>C:\Windows\system32\KERNELBASE.dll</Data>
<Data>0c124612-7c89-11e5-befb-50b7c3624f32</Data>
<Data>
</Data>
<Data>
</Data>
</EventData>
</Event>
Log Name: Application
Source: .NET Runtime
Date: 27-Oct-15 11:59:36 AM
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: AUDITOR
Description:
Application: TrueAsset.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Stack:
at Inventory_Management_System.Program.Main()
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name=".NET Runtime" />
<EventID Qualifiers="0">1026</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2015-10-27T08:59:36.000000000Z" />
<EventRecordID>66460</EventRecordID>
<Channel>Application</Channel>
<Computer>AUDITOR</Computer>
<Security />
</System>
<EventData>
<Data>Application: TrueAsset.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Stack:
at Inventory_Management_System.Program.Main()
</Data>
</EventData>
</Event>
Technology News @ www.JassimRahma.com
|
|
|
|
|
Well, as we have no idea at all what files your application is using, there's no possible way we can answer this. What I would suggest is that you add unhandled exception handling at the top of your application (e.g. AppDomain.UnhandledException or Application.ThreadException ). Log in here, the trace of where your code failed.
|
|
|
|
|
Probably your app depends on a DLL that is not signed properly (maybe delay-signed?)
But yeah, we'd definitely need more info to give you a more informed answer.
Best,
John
|
|
|
|
|
Well, in your second event log there is a FileNotFoundException in your Main method, so there's a start.
It's impossible to be any more specific with the information you've given.
|
|
|
|
|
Hello,
I'm working on a Winforms multithreading application.
I need some control over the thread(s) with a start and stop button. So to start and stop running the threads.
I have a list with places on a gui map and want to iterate the list but while iterating places can be added on the list and i have to sort them by by distance.
My question is can i do this with 2 threads or do i need more? And how can i start/pause threads? So when i add places to the list before starting nothing should happen only the sorting part. When pressing the start button the list need to be iterated.
|
|
|
|
|
Synchronization is essential when you have one thread modifying a datum while another thread is reading it. If I understand your design correctly, you have the following threads:
- The GUI thread (reads the shared structure and displays the map)
- Working thread(s) (update and sort the shared structure)
You may only have one GUI thread in a program, so the number of readers is fixed. The number of writers is variable, but unless there are special conditions that you are not telling us about - one writer thread should be sufficient.
Locking/Synchronisation between the two threads is left as an exercise for the student. Look up "Threads" and "Synchronisation Primitives" in any decent C# book.
The best way to terminate the working thread is to set some sort of flag that is checked by the working thread, which causes the thread to shut itself down cleanly. Terminating a thread any other way is asking for trouble.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
+5 Daniel, this is, as I would expect from any code/comment from you, five-worthy; the one thing I wonder about is:
In this scenario, when the update/sort thread does anything that changes the "display list:" at that point, doesn't the reading-the-list thread have to not only terminate, but reset (discarding its current whatever state-data representation) ?
And, then the reading-the-list thread has to "start over" when the update/sort thread finishes ?
Just curious if there is an order of complexity (the interdependency of the threads in terms of logic) here.
thanks, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Not unless the display must be updated within a very short time of the map update (e.g. well under 1 second).
What you need is some sort of event that notifies the GUI thread that an update has occurred. The GUI thread may then (in its own good time) take a "snapshot" of the data, and process it. Note that this is an event like any other, so it should fit nicely into the event-driven model used by the GUI thread.
Assuming that any single update of the map does not consume too much processor time, this will appear transparent to the user. At most, the display will lag slightly behind the updates if many updates are to be performed at the same time.
If you use blocking synchronization, the trick is to ensure that (a) the writing thread does not block the GUI thread for too long, and (b) that neither thread crashes while holding the lock. If you use "lock-free" methods, these problems go away.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|