|
Methinks this should do it:
bool InWebApp()
{
return (HttpContext.Current != null);
}
/ravi
|
|
|
|
|
Thanks but HttpContext seems to only be defined in the context of a web page. I'm looking to make this determination in a static class.
|
|
|
|
|
Create a property in your Utility class and use it to determine from which type of App it was called from.
None the less, you will have to set the value of thsi property from you app
|
|
|
|
|
Having done a few more experiments, I think either
AppDomain.CurrentDomain.FriendlyName.Contains("vshost.exe");
-windows app seems to have vshost.exe in that string, web apps have a guid
or
rc = AppDomain.CurrentDomain.DomainManager == null;
-windows apps have a domain manager, for web apps it seems to be null.
Guess I will go with one of these until it fails.
|
|
|
|
|
k666 wrote: AppDomain.CurrentDomain.FriendlyName.Contains("vshost.exe");
This wont work. This is due the fact that you are running you win app from visual studio.
k666 wrote: rc = AppDomain.CurrentDomain.DomainManager == null;
Even this wont work This may or may not be true depending upon the case.
Try using my previous reply.
|
|
|
|
|
Your reply essentials says set a flag from code. I would prefer that the determination be automatic and how would I ensure that the flag gets set before it is ever used?
|
|
|
|
|
The other thing you could do is to check the Uri object.
In web, it should return you the address from where it was called else I suppose it would be null or could throw an exception.
|
|
|
|
|
Uri is a class.
I don't see any static properties/routines that fit the ticket and new Uri() works fine in windows apps if I give it a valid address.
|
|
|
|
|
Hi,
I am refreshing a page every 3 min. for data update using:
this.Response.AppendHeader("Refresh", "180");
in the Page_Load event.
If no activity is detected the page should timeout forcing users to login again. The timeout is set for 20 mim. that never happens because of the 3 min refresh time.
How can I achieve both the auto refresh and timeout?
Thanks for your time
PS: this.Page.Session.Timeout - does not work???? or does it? if so how?
|
|
|
|
|
|
There is basically two solutions:
1. Get the data without reloading the page (e.g. using AJAX) from a session-less page. This of course means that the data that you get can't rely on any session variables.
2. Send some data along when you refresh the page, so that you can differentiate between the automatic refreshes and user activity. This means that you can't rely on the session timeout for the timeout. You have to handle it all yourself, keeping record of the last (non-automatic) request from the user.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
textbox.length propriety
There´s no need to create a new control, just validade with code.
If you know how to connect to a database what is your problem there?
Float, Int, Datetime i work them almost the same way, no special atention.
Do you already have done the connection to your database?
What do you have done so far?
nelsonpaixao@yahoo.com.br
|
|
|
|
|
The database connections are created using DataSets that are bound to controls to those tables and tableadapters within the dataset. Generally using a binding navigator to cycle through the records where needed.
|
|
|
|
|
I have a base form type which contains my delegate type definitions as well as standard routines that maybe used througout the application. On initialization of the base form I wire up an Update event which is triggered after I receive return data from a webservice call. The idea is to trigger the event within each running instance of the base form. I am accomplishing this now by iterating a foreach loop and firing the event seperately each time. Execution of this process can be greater than 40 seconds depending on how many forms are currently open. Is there a way of incorporating a multicast delegate to assist in triggering the events rather than the bloated foreach loop?
|
|
|
|
|
danielgmx wrote: this process can be greater than 40 seconds depending on how many forms are currently open.
danielgmx wrote: rather than the bloated foreach loop?
If I understand what you said, the root problem might be the number of forms. How many are there?
led mike
|
|
|
|
|
The form count is unknown, the forms are dynamically created from the base form via webservice response data. Here is an example of my code.
<pre>//the base form..
public delegate void SummaryDataChanged(object sender, SummaryDataChangedEventArgs e);</pre>
<pre>public virtual event SummaryDataChanged SummaryDataChangedEvent;</pre>
<pre>[STAThread()]
public ClassSpf.DataManager.ActivityReturn AnalyzeWebRequest(ClassSpf.DataManager.ActivityReturn.ActivityFlag flagType, ClassSpf.WebTargets.ProcessActivityDelegate webRequest, ClassSpf.DataManager.SpfGenericParameter genericParameter)
{
IAsyncResult iAsyncResult = webRequest.BeginInvoke(genericParameter, AnalyzeWebRequestCallBack, null);
ClassSpf.ActivityReturn activityReturn = webRequest.EndInvoke(iAsyncResult);
if (activityReturn.OutPut.Reqstatustx != string.Empty)
{
IssueMessage(activityReturn.Output);
}
if (activityReturn.ActivityException != null)
{
ClassAppTrace.HandleSystemException(activityReturn.ActivityException);
}
if (flagType == ActivityReturn.ActivityFlag.IssueUpdate)
{
if (ClassSpf.GlobalMemorySlots.Order != null && ClassSpf.GlobalMemorySlots.Operation != null)
{
this.QueueLoadSummary();
}
}
return activityReturn;
}
</pre>
<pre>
internal void QueueLoadSummary()
{
System.Threading.WaitCallback waitCallBack = new WaitCallback(LoadSummaryInformation);
System.Threading.ThreadPool.QueueUserWorkItem(waitCallBack);
}
</pre>
<pre>protected void LoadSummaryInformation(object stateInfo)
{
try
{
if (ClassSpf.GlobalMemorySlots.Input == null)
{
//well we can not load the summary data with out input now can we.
return;
}
else
{
ActivityReturn activityReturn =
WebServiceCall(ClassSpf.GlobalMemorySlots.Input, ref dataManager);
if (activityReturn.ActivityException == null)
{
if (dataManager.CurrentOrder != null & dataManager.CurrentOperation != null)
{
if (SummaryDataChangedEvent != null)
{
SummaryDataChangedEvent(this, new SummaryDataChangedEventArgs(dataManager));
}
SummaryDataChangedEventArgs summDataChanged = new SummaryDataChangedEventArgs(dataManager);
SummaryDataChangedEvent += new SummaryDataChanged(FormBase_SummaryDataChangedEvent);
SummaryDataChangedEvent(this, summDataChanged);
}
}
}
}
catch (InvalidOperationException iOx)
{
ClassAppTrace.HandleSystemException(iOx);
}
}</pre>
<pre>
FormBase_Load()
{
this.UpdateOccurredEvent += new SummaryDataChanged(FormBase_UpdateOccurredEvent);
}</pre>
//the mdiparent (inherited from base form)
<pre>private void MdiParent_SummaryDataChanged(object sender, SummaryDataChangedEventArgs e)
{
try
{
this.Invoke((MethodInvoker)delegate
{
//Some grid code goes here unimportant to the question
});
}
catch (Exception eX)
{
ClassAppTrace.HandleSystemException(eX);
}
finally
{
try
{
//Hook the event in to each child window that needs to accept it
foreach (FormBase child in this.MdiChildren)
{
(child as FormBase).OnUpdateOccurred(sender, e);
}
}
catch (Exception eX)
{
ClassAppTrace.HandleSystemException(eX);
}
}
}
</pre>
I am trying to change the foreach (FormBase child) loop to something more robust, I just don't know what now I imagine the issue is when the update is fired it is triggered by a child form thus only triggering the event for that form. I would like something like this.
Delegate UpdateType(Data Arguments);
Event UpdateType UpdateEvent;
FormBase_Load()
{
this.UpdateEvent += new UpdateEvent();
}
FormBase_TriggerChildUpdate(DataArgs e)
{
//this is where I would like to see all of the instantiated forms events fired.
//I am just not familiar enough with delegates to find a way to do so without the loop
if(UpdateEvent != null)
UpdateEvent(e);
}
|
|
|
|
|
danielgmx wrote: The form count is unknown
When it takes 40 seconds you don't know what the count is? Can't you do some debugging to find out?
led mike
|
|
|
|
|
The test case was 4 forms. I don't mean to be ignorant, but I suppose I am missing your reasoning? I will not always have 4 forms, I could have many. So delivering a count is irrelevant again unless there is something your not telling me.. Is there a limit to eventhandlers that I am not aware of?
|
|
|
|
|
danielgmx wrote: The test case was 4 forms.
Well that wasn't what I expected. I don't understand how 4 forms can take 40 seconds, that seems unreasonable, unless perhaps each form has a 1000 controls to update or something that is sucking the life out of the process. I must be missing something here because this just doesn't make sense.
led mike
|
|
|
|
|
Sounds to me like the problem is processing time within the delegate handlers, not the foreach loop which would be very quick. You could try calling each delegate asynchronously, but a better solution would probably to change how the delegate code is handled.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
You make a valid point, I appreciate your insight.
|
|
|
|
|
Hi,
I had written a webservice..which is working fine. This webservice will reside in server.
Now if I have make this webservice work for multiple servers.
Right now Iam adding a webrefernce to my application which is consuming webservice.
if this webservice has to be utilised globally..then what I have to do?
If I have to host the same webservice on different servers that leads to waste memory..since in all web methods in all the webservices have same logic and same datatype.
1.To make the same webservcie work on mutiple servers....
2. How add web refernce globally through programatically
3. If to make the webservcie work globally what are the paarameters I have to pass for them?.
4. what is best mechanism to check whether server running or down?
Kindly help me in achieving above
So kindly tell me wat is the best way..
|
|
|
|
|
you have put the same question in asp.net forum also and that was the right place .
cheers,
Abhijit
|
|
|
|
|
Below pasted is the piece of code where I want to display records based on the date range.
Let's say I have a startDate(01/15/2007) and an endDate(01/15/2008):
Can anyone give me some inputs as how to handle date validation in this code. I mean the place where I'm concatenating those 4 columns and getting a single date column row by row, I want to have this date validation. If it falls within this range, it shud add to the DataSet as a new row or else no.
DataSet newPDS = new DataSet();
DataRow row = new DataRow();
<code>
<code>
if (newPDS.Tables[0].Columns["ADM_DATE"]== null)
{
DataColumn dCol = new DataColumn(newPDS.Tables[0].Columns.Add("ADM_DATE", typeof(DateTime), "").ToString());
}
for(Int32 i = 0; i < newPDS.Tables[0].Rows.Count; i++)
{
row = newPDS.Tables[0].Rows[i];
<code>
row["ADM_DATE"] = row["CADMMM"] + "/" + row["CADMDD"] + "/" + row["CADMHH"] + row["CADMYY"];
}
Any help would be appreciated. Thanking you in anticipation.
modified on Wednesday, August 6, 2008 3:34 PM
|
|
|
|