|
It would be best if you didn't post your email address is a public forum. The only people who care about it, or are going to ever use it, are spammers. Yes, they have bots that scan forums for anything that looks like an email address and adds it to their databases to throw tons of "male enhancement" spam at you.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
How can i reverse this function so when i pass the output i get back the input
Dim text2 As String = ""
Dim num As Integer = 1
Dim num2 As Integer
Dim num3 As Integer
Do
' The following expression was wrapped in a unchecked-expression
Dim value As Integer = CInt(Math.Round(Math.Floor(CDbl((10.0F * VBMath.Rnd())))))
text2 += Conversions.ToString(value)
num += 1
num2 = num
num3 = 8
Loop While num2 <= num3
|
|
|
|
|
You can only do so if you know what sequence the VBMath.Rnd()[^] function returns. That's something the function is not guaranteed to do, so you can't.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You can't reverse that function. Round and Floor are "lossy", meaning bits of data are lost when the functions are used on the data. It's impossible to get that data back and get the original number.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Hi there,
(Not sure which area to put this question in so forgive me)I have a word document but i'd like to convert it to HTML. I know i can convert from Microsoft Word to HTML document but are there any limitations or issues? if so what do i need to be aware of?
Can anyone suggest any suitable alternatives please?
|
|
|
|
|
Yeah, the limitations of HTML. Word can format individual elements of the document in ways that are not directly supported by HTML. You'll get a good approximation of the document, but the more complex the document, the more differences you're going to see.
The alternative is to "print" the document to a PDF file and send that to the client. If the browser has an extension to display PDF documents in the browser it'll display. If not, they'll get a prompt to open it in an external viewer or save the file.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
I have an eight core computer and therefor I can have a tasklist with 8 tasks.
But not al 8 task are perform correctly or something else doesn't work.
My objective: I want 8 count results be shown on a website (MVC) so I have 8 different methods that get the 8 result seperatly.
One method is like this:
protected void GetArticleCount()
{
ArticlesManager articlesManager = new ArticlesManager();
ViewBag.ArticlesCount = articlesManager.ArticleCount();
}
And so there are 7 more.
My code to collect all 8 is like this:
var t1 = Task.Factory.StartNew(() => GetArticleCount());
var t2 = Task.Factory.StartNew(() => GetBrancheCount());
var t3 = Task.Factory.StartNew(() => GetCompaniesCount());
var t4 = Task.Factory.StartNew(() => GetDeliveriesCount());
var t5 = Task.Factory.StartNew(() => GetDistributionCentresCount());
var t6 = Task.Factory.StartNew(() => GetDocksCount());
var t7 = Task.Factory.StartNew(() => GetInvoicesCount());
var t8 = Task.Factory.StartNew(() => GetOrdersCount());
var taskList = new List<Task> { t1, t2, t3, t4, t5, t6, t7, t8 };
Task.WaitAll(taskList.ToArray());
When I run it 5 off the 8 are visible on my website and the remaining 3 are also shown after a refresh (F5).
When I run the code without the "Task.Factory" but sequentially, all 8 are shown immediately.
Question: why? What's wrong with my code?
|
|
|
|
|
Nothing is wrong. But you need to understand that starting a new task does not automatically start it immediately in a new core. The operating system queues tasks for processing them and starts them when resources are available.
|
|
|
|
|
Okay, so this is a "problem" because it does not give the result I want.
Thanks for your reply, I know what to do.
|
|
|
|
|
"Refresh rate" is not necessarrily tied to when your tasks are finishing.
I would use something "other" to determine when tasks actually finish than when it "shows up".
Your "tasks" look like queries; some will probably always run last. You should see a pattern.
Even too many (redundant) refreshes can affect overall performance (flicker; bouncing cursor).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
You are completely right Gerry 
|
|
|
|
|
Trace.WriteLine() and a StopWatch help me with timings...
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi
I need to read xml values using Key in power shell
|
|
|
|
|
Go ahead then, you have our permission.
|
|
|
|
|
I am using webapi in my mvc project and when ever I made a request from browser to api call I am getting the following error:
And i am using the .netFramework 4.0
Exception Details:
Server Error in '/' Application.
The format of value 'application/json; charset=utf-8' is invalid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: The format of value 'application/json; charset=utf-8' is invalid.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[FormatException: The format of value 'application/json; charset=utf-8' is invalid.]
System.Net.Http.Headers.MediaTypeHeaderValue.CheckMediaTypeFormat(String mediaType, String parameterName) +119919
System.Net.Http.Headers.MediaTypeHeaderValue..ctor(String mediaType) +23
System.Net.Http.ObjectContent.BuildHeaderValue(String mediaType) +63
System.Net.Http.ObjectContent`1..ctor(T value, MediaTypeFormatter formatter, String mediaType) +66
System.Net.Http.HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage request, HttpStatusCode statusCode, T value, HttpConfiguration configuration) +892
System.Net.Http.HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage request, HttpStatusCode statusCode, T value) +104
System.Web.Http.Dispatcher.HttpControllerDispatcher.HandleException(HttpRequestMessage request, Exception exception, HttpConfiguration configuration) +191
System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +284
System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +41
System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +347
System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +55
System.Web.Http.WebHost.HttpControllerHandler.BeginProcessRequest(HttpContextBase httpContextBase, AsyncCallback callback, Object state) +316
System.Web.Http.WebHost.HttpControllerHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +77
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I searched in google but can't find the proper solution.
Please help me
|
|
|
|
|
You need to check the server to see why it cannot handle your request. And it would help if you showed the actual request that you sent, in your question.
|
|
|
|
|
Sorry but how can i check the server to verify the requests
|
|
|
|
|
No idea, it's your server.
|
|
|
|
|
Where are you hosting your Web API services? Are they on Azure, IIS etc? How are they configured?
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Home | LinkedIn | Google+ | Twitter
|
|
|
|
|
|
There isn't enough information here. Giving us the error message tells us very little.
- What parameters are you passing to the Web API?
- Is this a GET, POST etc
It would be useful to see the code that calls the Web API (the client code) and the Web API code itself (the server code).
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Home | LinkedIn | Google+ | Twitter
|
|
|
|
|
Hello everyone, back to coding after a long absence so excuse my rustiness
When doing database apps ibe allways done the wrong thing & validated user input on the form, via simple checks against the controls .text property. Now i want to do it the right way, and concentrate all validation closer to the data side of things, in this case the data tables.
So i decided to do it via the RowChanging event:
On my table...
public override void EndInit()
{
base.EndInit();
customersRowChanging += customersRowChangeEvent;
}
public void customersRowChangeEvent(object sender, customersRowChangeEvent e)
{
if (e.Row.Name.Length == 0)
{
e.Row.SetColumnError("name", "Customer name cannot be empty");
}
else
{
e.Row.SetColumnError("name", "");
}
}
On my app, in a form the textboxes & other input are bound to a BindingSource, wich in turn is bound to the datatable in the dataset (100% as per visual studio designer).
To add a record,
I call the BindingSource.AddNew(), and allow the user to enter the data and then on my handler for the "Save" button...
try
{
Validate();
customersBindingSource.EndEdit();
customersTableAdapter.Update(samDataSet.customers);
}
catch(Exception ex)
{
}
Even without handling the rowChange event, This works when a datatable or database constraint is violated, e.g. if the name is NULL or not unique (as specified in the data table constraints), an exception occurs, and the record is not saved.
However, Even with the RowChangeEvent implemented as above, if a record with an empty (not null, empty string) name is in the record, no exception is thrown, the datatable gladly accepts the new record, and the table adapter saves it (the MySQL database does not enforce empty string values).
Ibe checked, and the handler does get called, and the call to SetColumnError is made, but it doesnt prevent the table from accepting the new row.
I read to use this method from here: Validate data in datasets[^]
And i was under the impression that when i call SetColumnError() with a non empty string for error, the table would not accept the new row. Evidently i got it wrong.
Ibe also tried throwing an exception myself if the data fails the validation requirements, like this:
public void customersRowChangeEvent(object sender, customersRowChangeEvent e)
{
if (e.Row.Name.Length == 0)
{
e.Row.SetColumnError("name", "Customer name cannot be empty");
throw new System.Exception("Customer Name cannot be empty");
}
else
{
e.Row.SetColumnError("name", "");
}
}
But the Binding source does not catch & (re) throw the exception to my own code when it tries to commit the new record, because i end up with an unhandled exception.
Of course there are 101 ways i could enforce data validation on the form, or creating specific bool ValidateThis(DataRow theData) methods, but i would depend on calling such methods every time, and i would prefeer the tables to enforce their own rules automatically.
Can anyone see why its not working?
If calling the SetColumnError doesnt prevent the table from accepting the row, then whats the point of calling it to set errors?
Maybe im doing it the wrong way?
Any input much appreciated!
modified 9-Nov-17 0:27am.
|
|
|
|
|
I've never had input-validation on a DataTable ; usually there is a (generated) validation in the UI, and another one in the database itself. Yes, they partially overlap.
If your DataTable HasErrors , you could try to RejectChanges[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for the reply Eddy.
I just found out whats wrong...
This:
public void customersRowChangeEvent(object sender, customersRowChangeEvent e)
{
if (e.Row.Name.Length == 0)
{
e.Row.SetColumnError("name", "Customer name cannot be empty");
throw new System.Exception("Customer Name cannot be empty");
}
else
{
e.Row.SetColumnError("name", "");
}
}
Does work as intended. The unhandled exception i was getting was a First chance exception. If i hit continue and let the code continue to run, it does get handled properly on my own try / catch statements on the Save button handler i posted above.
Now i feel embarassed. i guess im rustier than i tought i was. I completely forgot about first chance exceptions and how the debuger handles them.
|
|
|
|
|
Hehe, I recognize those days
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|