|
Mike Bluett wrote: update a control programmatically.
What do you mean? What are trying to accomplish? Typically you would create a method in the form class to call and manipulate the control from there.
only two letters away from being an asset
|
|
|
|
|
I have updated my original posting in order to try and make it more clear. Hope this helps.
|
|
|
|
|
As I said before, the typically you would expose a method on the form to update and manipulate the control.
This is an advanced topic that seems to be above your level of skill, I suggest you do more research and learn more about forms and controls before you continue.
only two letters away from being an asset
|
|
|
|
|
It should not be an advanced topic!!
This is something ANY programmer would want to do with almost ANY program.
Besides before posting here I have done extensive reading in all kinds of C# books and resources and cannot find an answer to my problem. Basically, I am trying to understand why Microsoft would create such a complicated approach to doing what should be incredibly simple.
What I want to do is simply use a GLOBAL reference to Form1 so that I can setup an object reference to Form1 so that it can be accessed from another method within the Program class (or in my case the FileOrganizer class).
I am forced to use the "Application.Run" method; otherwise, the application will quit after it finishes executing my code. The Microsoft template places the "Run" call within Main. Because Main must be static, it will not let me create a GLOBAL reference to "Form1". I can create an object reference to Form1 within Main; however, it is not GLOBAL and I cannot access it from another method in the FileOrganizer class.
I am sure that Microsoft, in their infinite wisdom, provided a mechanism to accomplish this in a simple fashion; however, it is not obvious to me.
I had previously written another program (which I started in SharpDevelop). In this program, all of the modifications to the main form are done through events.
However, in my current program, there are no events that get fired (i.e., mouse clicks). What I am doing is reading some data from a database trying to use that data to populate a TreeView (which resides on the main form).
If I could create a GLOBAL variable, this would be incredibly simple to implement. Because I can't this becomes a major complication. Why it has to be this complicated is beyond me; however, I am willing to spend the time to understand it.
If you know of some code I can reference in some book or some web reference that can help me to understand this I would be very grateful.
|
|
|
|
|
Mike Bluett wrote: I have done extensive reading in all kinds of C# books and resources
It is quite obvious your research has been lacking. It is also quite apparent you don't have sufficient understanding of Windows programming to tackle this task. It is relatively easy to do and you have been given the answers, pay attention.
Mike Bluett wrote: I am forced to use the "Application.Run" method
Correct, this is the way a Windows app is started. If you had the knowledge of this environment you would understand that. Form1 (or whatever you name it) is the application, not Program!
Mike Bluett wrote: Why it has to be this complicated is beyond me
Yes it is. Hire someone to do it for you.
Mike Bluett wrote: If you know of some code I can reference
Have your looked here[^]
Since its Christmas Eve here, maybe you can hope Santa will bring you a clue, or at least a fully functional app all wrapped up in a pretty bow for you. Otherwise, I would suggest you stop complaining and actually learn the subject.
only two letters away from being an asset
|
|
|
|
|
Since it is Christmas I would think you would be a little more civil than you have been!!!
My research maybe lacking and that is why I came to this forum to get me on the right track, but all I have been greeted with is ARROGANCE!!!
I think you should take a couple of long breaths and relax a little. It might help your composure.
Merry Xmas!!
|
|
|
|
|
Do not get it. Can you clarify the question again and tell us what you were trying to do in a sentence?
LuckyBoy
|
|
|
|
|
This sentence was copied from my previous post:
"What I want to do (within another method of the FileOrganizer class) is to update a control programmatically."
For example, I want to add some nodes to a TreeView control.
So, this is what I want to do; however, you will not be able to respond with an appropriate answer unless you read through my previous post entirely.
|
|
|
|
|
Mike Bluett wrote: For example, I want to add some nodes to a TreeView control.
If you want to do this, why donot you put the update control method in the mainform constructor? Maybe I misunderstood you question. However, this is not common to initialize the control in this way for windows form app.
LuckyBoy
|
|
|
|
|
Maybe I wasn't clear enough. This is not about initialization. This is about modifying controls after initialization.
Controls should be able to be modified anywhere within the program and at any time while the program is running.
|
|
|
|
|
Yes, however, you cannot update a control from a thread other than the main UI thread. A well documented fact of Windows UI work. There are plenty of examples, here and elsewhere, about adding nodes to a treeview, I suggest you do a little research.
only two letters away from being an asset
|
|
|
|
|
I found the answer on another forum.
All I needed to do was to make the GLOBAL definition static due to the fact that the the method it is called from is static. Very simple as I expected it might be.
Code as follows:
public class FileOrganizer<br />
{<br />
private static Form1 mainForm;<br />
<br />
<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.EnableVisualStyles();<br />
Application.SetCompatibleTextRenderingDefault(false);<br />
mainForm = new Form1();<br />
Application.Run(mainForm);<br />
}
It's amazing how much of a run-around I was given on this forum.
|
|
|
|
|
Please help in solving my problem
Problem: I have an application, which was developed in combination of managed and unmanaged code, no method or function is exposed to the external world from unmanaged code.
but I found that there are some public functions availabe in managed code(again which are not static). which will gives the information which i required.
now i need to hook those managed c# functions and re-route them to my own function and then route it original path.
i heard something about "Profiling API Enter/Leave", is it possible to workout with this, if possible how to do that?
I am an Automation TestEngineer, i dont have any in-depth knowledge in all these...
desperately in need, please help me
Thanks for kind replies
Surya.
|
|
|
|
|
venkatcontact wrote: desperately in need
... of a clearer explanation
only two letters away from being an asset
|
|
|
|
|
Hi,
VS2005 C# WinForms
I have an app.config file which has a number of configurations (as well as the appSettings sections) there are a number of other custom config sections in the file and references to web services.
Due to the remoteness of many of the client apps I would like to maintain all the configurations in the database.
The idea is to generate the xml file at runtime, save it and then use that throughout the app.
Ive seen how I can set the appSettings sections at runtime -
http://www.codeproject.com/KB/cs/runtimeconsoleconfigfile.aspx
but is it possible to set the entire config file at runtime - including all my custome object sections and web references?
Thanks,
Chas
|
|
|
|
|
|
Hi All,
I am able to install and run the windows service on Win XP. Howeer, I cannot install the .NET 2.0 Windows service on Win2008 server. I have the following modules being called by Windows Service: i. A webservice application hosted on the same server. ii. Using a .NET 3.5 class library DLL to send emails (System.Net).
Below is the Install Log error:
Installing assembly 'C:\SMSWindowsService\bin\DataOnline.SMSWindowsService.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\SMSWindowsService\bin\DataOnline.SMSWindowsService.exe
logfile = C:\SMSWindowsService\bin\DataOnline.SMSWindowsService.InstallLog
Installing service DOL SMS Windows Service...
Creating EventLog source DOL SMS Windows Service in log Application...
Rolling back assembly 'C:\SMSWindowsService\bin\DataOnline.SMSWindowsService.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\SMSWindowsService\bin\DataOnline.SMSWindowsService.exe
logfile = C:\SMSWindowsService\bin\DataOnline.SMSWindowsService.InstallLog
Restoring event log to previous state for source DOL SMS Windows Service.
An exception occurred during the Rollback phase of the System.Diagnostics.EventLogInstaller installer.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
An exception occurred during the Rollback phase of the installation. This exception will be ignored and the rollback will continue. However, the machine might not fully revert to its initial state after the rollback is complete.
|
|
|
|
|
I'm writing an app that updates an Access database i am currently using Jet OLEDB connection to run my update querys. My app is parsing a large amount of data and takes about 10 - 15 mins to complete. I have noticed that If i try to access the DB from access while the app is running the Database is locked. Is there a way I can open the DB with out locking the DB for any other write access?
thanks
MAconn = new OleDbConnection();
MAconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source="+DBPath;
MAconn.Open();
MAcmd = MAconn.CreateCommand();
conn_succ = true;
|
|
|
|
|
Nope. If you wanted this kind of functionality, you'd have to move to SQL Server or an equivilent. My personal choice would be SQL Server Express.
|
|
|
|
|
Thanks, that is what i thought was the answer was but wanted to double check.
|
|
|
|
|
Planker wrote: Is there a way I can open the DB with out locking the DB for any other write access
It's been awhile since I last used Access, but when using ADO there was several parameters for the connection string you could specify which would affect how the Access db works.
The records you update will be locked, but if you're not able to open the database using another connection, sounds like the db has been opened in exclusive mode.
You could see the following if there's any help: ADO Provider Properties and Settings[^]
However, if you're going to use the db seriously, I'd also suggest you move on to SQL Server.
|
|
|
|
|
It's not so much accessing the database from another instance of the app as the problem is Access opens the database DenyShareWrite. His explanation was that he couldn't open the database in Access and still have database writes be made by his application.
|
|
|
|
|
Dave Kreskowiak wrote: explanation was that he couldn't open the database in Access and still have database writes be made by his application.
I understood that and I got the feeling that the first connection to the db (his application) opens it in exclusive mode for some reason.
Perhaps I'm still missing something, but I made a test with a fresh db with only 1 table (Table1) where I tried to simulate the problem:
System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\...\db1.mdb";
connection.Open();
System.Data.OleDb.OleDbCommand command = connection.CreateCommand();
System.Data.OleDb.OleDbTransaction transaction = connection.BeginTransaction();
command.Transaction = transaction;
command.CommandText = "INSERT INTO Table1 (Field1) VALUES ('A')";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO Table1 (Field1) VALUES ('B')";
command.ExecuteNonQuery();
transaction.Commit();
Before the commit I stopped the debugger. While still in debug mode I opened the mdb file from Access 2003 UI and then opened Table1. Didn't see the rows A and B as expected but all the previous rows where present. When I went through the commit and then re-opened Table1 rows A and B were present.
So all the time I was able to for example query the table. Also I was able to modify data in another table while transaction from C# was in action. Didn't try to update the same table since I suspect that when using defaults, page level locking is used.
|
|
|
|
|
Hi i write a piece of code that is used to get the event log of the Window. and then i get the log Entries
EventLog[] logs = EventLog.GetEventLogs();
foreach (EventLog log in logs)
{
foreach (EventLogEntry entry in log.Entries)
{
if ((entry.EntryType == EventLogEntryType.Error)
|| (entry.EntryType == EventLogEntryType.Warning)
|| (entry.EntryType == EventLogEntryType.FailureAudit))
{
if (lastUpdate.CompareTo(entry.TimeGenerated) < 0)
x.addEvent(entry);
}
}
}
Know when i execute this code on server
it take 60% to 70 % of the CPU . Please give me any idea to make it more efficent so that it take 10 to 20% of CPU
WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP
|
|
|
|
|
Reading the event logs shouldn't be that intensive. I suspect the bottleneck lies around x.addEvent.
|
|
|
|